Django'功能'对象没有属性' get'

时间:2014-12-12 04:35:45

标签: django

我遇到了这个错误:

'function' object has no attribute 'get'

通过点击劫持看起来似乎正在发生

这是完整的追溯

Request Method: GET
Request URL: http://localhost:8000/weblog/categories/weekly/

Django Version: 1.7
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'django.contrib.flatpages',
 'search',
 'coltrane',
 'tagging',
 'markdown')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
  204.                 response = middleware_method(request, response)
File "/Library/Python/2.7/site-packages/django/middleware/clickjacking.py" in process_response
  31.         if response.get('X-Frame-Options', None) is not None:

Exception Type: AttributeError at /weblog/categories/weekly/
Exception Value: 'function' object has no attribute 'get'

我的观点和网址:

url(r'^(?P<slug>[-\w]+)/$', 'coltrane.views.category_detail', {},
    name='coltrane_category_detail'),

def category_detail(request, slug):
category = get_object_or_404(Category, slug=slug)
return  ListView.as_view(queryset=category.live_entry_set(),
                         context_object_name={'category': category})

2 个答案:

答案 0 :(得分:18)

as_view()方法返回需要使用request参数调用的视图函数:

return ListView.as_view(.....)(request)

答案 1 :(得分:1)

您转发的视图可能不会处理GET请求。 调整你的视图就像:

class logout_view(View):
def get(self,request):
    logout(request)
    return redirect('appname:view')