Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 'function' object has no attribute 'get'

Tags:

django

I've run into this error:

'function' object has no attribute 'get'

Which looks like it is occurring with clickjacking

Here is the full traceback

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'

My View and URL:

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})
like image 297
byrdr Avatar asked Dec 12 '14 04:12

byrdr


2 Answers

as_view() method returns view function which you need to call with request argument:

return ListView.as_view(.....)(request)
like image 51
catavaran Avatar answered Nov 14 '22 01:11

catavaran


It is Probably the view you are forwarding to doesn't handle GET requests.. Tweak your View to little like:

class logout_view(View):
def get(self,request):
    logout(request)
    return redirect('appname:view')
like image 35
Deepak Sharma Avatar answered Nov 14 '22 01:11

Deepak Sharma