Django Attribute Error: 'function' object has no attribute 'is_usable'
I am setting up a Django blog. I followed these instructions and I am getting the following error:
Environment:
Request Method: GET
Request URL: http://url.com/
Django Version: 1.6.2
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
'divinare',
'rest_framework',
'django_facebook',
'django.contrib.auth')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/home/spencer/webapps/hello_django/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
139. response = response.render()
File "/home/spencer/webapps/hello_django/local/lib/python2.7/site-packages/django/template/response.py" in render
105. self.content = self.rendered_content
File "/home/spencer/webapps/hello_django/local/lib/python2.7/site-packages/django/template/response.py" in rendered_content
80. template = self.resolve_template(self.template_name)
File "/home/spencer/webapps/hello_django/local/lib/python2.7/site-packages/django/template/response.py" in resolve_template
56. return loader.select_template(template)
File "/home/spencer/webapps/hello_django/local/lib/python2.7/site-packages/django/template/loader.py" in select_template
180. return get_template(template_name)
File "/home/spencer/webapps/hello_django/local/lib/python2.7/site-packages/django/template/loader.py" in get_template
138. template, origin = find_template(template_name)
File "/home/spencer/webapps/hello_django/local/lib/python2.7/site-packages/django/template/loader.py" in find_template
121. loader = find_template_loader(loader_name)
File "/home/spencer/webapps/hello_django/local/lib/python2.7/site-packages/django/template/loader.py" in find_template_loader
104. if not func.is_usable:
Exception Type: AttributeError at /
Exception Value: 'function' object has no attribute 'is_usable'
Middleware:
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
#'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
Template Loaders:
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.contrib.auth.context_processors.auth',
# 'django.template.loaders.eggs.Loader',
)
Any insights to what is causing the error would be very helpful.
Your problem is almost certainly that you have "django.contrib.auth.context_processors.auth" in your TEMPLATE_LOADERS setting. As the name implies, that's a context processor, not a template loader - it should go in TEMPLATE_CONTEXT_PROCESSORS.
Related
I am new to Django, and I just took over from another developer on this project. All I have done so far is clone the code from git and install the dependencies.
Immediately after setting up the project, and running python manager.py runserver and going to localhost:8000/admin I get an error stating the TypeError at /admin/login/, 'CsrfViewMiddleware' object is not iterable:
Traceback:
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/exception.py"
in inner
39. response = get_response(request)
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/base.py"
in _legacy_get_response
249. response = self._get_response(request)
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/base.py"
in _get_response
217. response = self.process_exception_by_middleware(e, request)
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/base.py"
in _get_response
215. response = response.render()
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/response.py"
in render
109. self.content = self.rendered_content
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/response.py"
in rendered_content
86. content = template.render(context, self._request)
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/backends/django.py"
in render
66. return self.template.render(context)
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/base.py"
in render
206. with context.bind_template(self):
File "/usr/lib/python3.5/contextlib.py" in __enter__
59. return next(self.gen)
File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/context.py"
in bind_template
236. updates.update(processor(self.request))
Exception Type: TypeError at /admin/login/
Exception Value: 'CsrfViewMiddleware' object is not iterable
I would post code from the source code but I can't figure where in the source the cause of this might possibly be.
My settings.py:
import os
from datetime import datetime
from django.conf.global_settings import EMAIL_USE_SSL
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'ourapp',
'social.apps.django_app.default',
'sendgrid',
'corsheaders',
)
MIDDLEWARE_CLASSES = (
'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',
'ourapp.middleWare.authenticationMiddleware.AuthenticationMiddleware'
)
ROOT_URLCONF = ''
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.middleware.csrf.CsrfViewMiddleware',
'corsheaders.middleware.CorsMiddleware',
'social.apps.django_app.context_processors.backends',
'social.apps.django_app.context_processors.login_redirect',
],
},
},
]
(Sorry about the lack of indentation.)
Any ideas on how to proceed from here would be greatly appreciated!
Try removing 'django.middleware.csrf.CsrfViewMiddleware', from TEMPLATES. Probably 'corsheaders.middleware.CorsMiddleware', too
My Geocode application which is based on Django is no longer serving properly, and I am getting the error detailed as follows:
Environment:
Request Method: GET
Request URL: http://52.36.3.179/
Django Version: 1.6.11
Python Version: 2.7.6
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
'django.contrib.messages',
'django.contrib.humanize',
'django.contrib.gis',
'pagination',
'taggit',
'friendlytagloader',
'geoexplorer',
'leaflet',
'django_extensions',
'autocomplete_light',
'mptt',
'modeltranslation',
'djcelery',
'pinax_theme_bootstrap_account',
'pinax_theme_bootstrap',
'django_forms_bootstrap',
'account',
'avatar',
'dialogos',
'agon_ratings',
'announcements',
'actstream',
'user_messages',
'tastypie',
'polymorphic',
'guardian',
'geonode.people',
'geonode.base',
'geonode.layers',
'geonode.maps',
'geonode.proxy',
'geonode.security',
'geonode.social',
'geonode.catalogue',
'geonode.documents',
'geonode.api',
'geonode.groups',
'geonode.services',
'geonode.geoserver',
'geonode.upload',
'geonode.tasks')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
'pagination.middleware.PaginationMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
137. response = response.render()
File "/usr/lib/python2.7/dist-packages/django/template/response.py" in render
105. self.content = self.rendered_content
File "/usr/lib/python2.7/dist-packages/django/template/response.py" in rendered_content
81. context = self.resolve_context(self.context_data)
File "/usr/lib/python2.7/dist-packages/django/template/response.py" in resolve_context
159. return RequestContext(self._request, context, current_app=self._current_app)
File "/usr/lib/python2.7/dist-packages/django/template/context.py" in __init__
169. self.update(processor(request))
File "/usr/local/lib/python2.7/dist-packages/geonode/context_processors.py" in resource_urls
28. site = Site.objects.get_current()
File "/usr/lib/python2.7/dist-packages/django/contrib/sites/models.py" in get_current
47. current_site = self.get(pk=sid)
File "/usr/lib/python2.7/dist-packages/django/db/models/manager.py" in get
151. return self.get_queryset().get(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/db/models/query.py" in get
310. self.model._meta.object_name)
Exception Type: DoesNotExist at /
Exception Value: Site matching query does not exist.
I can provide more configuration settings if need be. Please don't hesitate to ask. I am trying to not have to reinstall the application. This problem happened after I reloaded the server in order to update the correct URL.
I upgraded django and all apps I was using to the recent version but because of the huge changes made between djangorestframework 0.4.0 and 3.3.0 I've returned to 0.4.0 and opted to fix the simpler issue it had importing json from django.utils and edited it to import json now I'm getting an error templatedoesnotexist
Environment:
Request Method: GET
Request URL: http://kbuzz.webfactional.com/rest/movies/?device=browser
Django Version: 1.7.10
Python Version: 2.7.9
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.redirects',
'django.contrib.humanize',
'autocomplete_light',
'rest_framework',
'haystack',
'lamusoftware.generic',
'mptt',
'bootstrapform',
'sorl.thumbnail',
'oauth2client',
'articles',
'banners',
'common',
'directory',
'events',
'galleries',
'marketplace',
'movies',
'pages',
'profiles',
'search',
'stats',
'minidetector',
'mobile',
'reports',
'favorites',
'braces',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'widget_tweaks',
'wordofmouth',
'ckeditor',
'django_mobile',
'debug_toolbar',
'markup_deprecated')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'minidetector.Middleware',
'mobileesp.middleware.MobileDetectionMiddleware',
'kb.middleware.log_ip_middleware.SetRemoteAddrFromForwardedFor',
'kb.middleware.log_ip_middleware.RedirectMovie')
Template Loader Error:
Django tried loading these templates, in this order:
Using loader django_mobile.loader.Loader:
Using loader django.template.loaders.filesystem.Loader:
/home/kbuzz/webapps/kenyabuzz/kb/kb/templates/djangorestframework/api.html (File does not exist)
Using loader django.template.loaders.app_directories.Loader:
/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/contrib/auth/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/contrib/sitemaps/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/contrib/admin/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/django/lib/python2.7/autocomplete_light/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/django/lib/python2.7/rest_framework/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/lib/python2.7/haystack/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/django/lib/python2.7/mptt/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/lib/python2.7/bootstrapform/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/kenyabuzz/kb/reports/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/kenyabuzz/kb/favorites/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/django/lib/python2.7/allauth/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/django/lib/python2.7/allauth/socialaccount/providers/facebook/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/kenyabuzz/kb/wordofmouth/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/lib/python2.7/ckeditor/templates/djangorestframework/api.html (File does not exist)
/home/kbuzz/webapps/django/lib/python2.7/debug_toolbar/templates/djangorestframework/api.html (File does not exist)
Traceback:
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/views/decorators/csrf.py" in wrapped_view
57. return view_func(*args, **kwargs)
File "/home/kbuzz/lib/python2.7/djangorestframework/views.py" in dispatch
246. return self.final(request, response, *args, **kwargs)
File "/home/kbuzz/lib/python2.7/djangorestframework/views.py" in final
199. return self.render(response)
File "/home/kbuzz/lib/python2.7/djangorestframework/mixins.py" in render
251. content = renderer.render(response.cleaned_content, media_type)
File "/home/kbuzz/lib/python2.7/djangorestframework/renderers.py" in render
342. template = loader.get_template(self.template)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/template/loader.py" in get_template
144. template, origin = find_template(template_name, dirs)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/template/loader.py" in find_template
136. raise TemplateDoesNotExist(name)
Exception Type: TemplateDoesNotExist at /rest/movies/
Exception Value: djangorestframework/api.html
UPDATE
I edited settings file from rest_framework to djangorestframework now getting this error mimetype must have been removed for httpresponse.
Environment:
Request Method: GET
Request URL: http://kbuzz.webfactional.com/rest/movies/categories/?device=browser
Django Version: 1.7.10
Python Version: 2.7.9
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.redirects',
'django.contrib.humanize',
'autocomplete_light',
'djangorestframework',
'haystack',
'lamusoftware.generic',
'mptt',
'bootstrapform',
'sorl.thumbnail',
'oauth2client',
'articles',
'banners',
'common',
'directory',
'events',
'galleries',
'marketplace',
'movies',
'pages',
'profiles',
'search',
'stats',
'minidetector',
'mobile',
'reports',
'favorites',
'braces',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'widget_tweaks',
'wordofmouth',
'ckeditor',
'django_mobile',
'debug_toolbar',
'markup_deprecated')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'minidetector.Middleware',
'mobileesp.middleware.MobileDetectionMiddleware',
'kb.middleware.log_ip_middleware.SetRemoteAddrFromForwardedFor',
'kb.middleware.log_ip_middleware.RedirectMovie')
Traceback:
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/views/decorators/csrf.py" in wrapped_view
57. return view_func(*args, **kwargs)
File "/home/kbuzz/lib/python2.7/djangorestframework/views.py" in dispatch
246. return self.final(request, response, *args, **kwargs)
File "/home/kbuzz/lib/python2.7/djangorestframework/views.py" in final
199. return self.render(response)
File "/home/kbuzz/lib/python2.7/djangorestframework/mixins.py" in render
256. resp = HttpResponse(content, mimetype=response.media_type, status=response.status)
File "/home/kbuzz/webapps/kenyabuzz/lib/python2.7/Django-1.7.10-py2.7.egg/django/http/response.py" in __init__
318. super(HttpResponse, self).__init__(*args, **kwargs)
Exception Type: TypeError at /rest/movies/categories/
Exception Value: __init__() got an unexpected keyword argument 'mimetype'
If you have switched back to rest framwork 0.4.0, you should change the value in your INSTALLED_APPS from rest_framework back to djangorestframework.
Then the app template loader should find the template in the djangorestframework/templates directory.
I try to access the Ip address using middleware request, Here is my sample code,
def process_request(self, request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[-1].strip()
else:
ip = request.META.get('REMOTE_ADDR') --> I am getting the error here
return ip
Here is my complete error trace:
Environment:
Request Method: GET
Request URL: http://localhost/admin/management/banipaddress/
Django Version: 1.6.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'utils',
'catalog',
'preview',
'cart',
'management')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'custom.middleware.banipmiddleware.BanIpMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/home/user/prodjango-env/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
201. response = middleware_method(request, response)
File "/home/user/prodjango-env/venv/local/lib/python2.7/site-packages/django/middleware/clickjacking.py" in process_response
30. if response.get('X-Frame-Options', None) is not None:
Exception Type: AttributeError at /admin/management/banipaddress/
Exception Value: 'WSGIRequest' object has no attribute 'get'
Error seems to be at another line
File "/home/user/prodjango-env/venv/local/lib/python2.7/site-packages/django/middleware/clickjacking.py" in process_response
30. if response.get('X-Frame-Options', None) is not None:
in clickjacking.py.
Don't know its yours. There is trying to access response.get() which is not correct.
I have installed django-avatar and django-notification (django-avatar uses django-notification, if the latter is installed, in order to send necessary messages to user).
However when I upload/change/delete my avatar I get this error:
Request Method: POST
Request URL: http://localhost:8000/avatar/change/
Django Version: 1.3
Python Version: 2.6.4
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'grappelli',
'filebrowser',
'tinymce',
'south',
'avatar',
'django.contrib.admin',
'notification',
'tipleaders.main']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "C:\Tools\Python26\lib\site-packages\django\core\handlers\base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "C:\Tools\Python26\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "C:\Tools\Python26\lib\site-packages\django_avatar-1.0.5-py2.6.egg\avatar\views.py" in change
77. notification.send([request.user], "avatar_updated", {"user": request.user, "avatar": avatar})
File "C:\Tools\Python26\lib\site-packages\django_notification-0.2-py2.6.egg\notification\models.py" in send
351. return send_now(*args, **kwargs)
File "C:\Tools\Python26\lib\site-packages\django_notification-0.2-py2.6.egg\notification\models.py" in send_now
276. reverse("notification_notices"),
File "C:\Tools\Python26\lib\site-packages\django\core\urlresolvers.py" in reverse
391. *args, **kwargs)))
File "C:\Tools\Python26\lib\site-packages\django\core\urlresolvers.py" in reverse
337. "arguments '%s' not found." % (lookup_view_s, args, kwargs))
Exception Type: NoReverseMatch at /avatar/change/
Exception Value: Reverse for 'notification_notices' with arguments '()' and keyword arguments '{}' not found.
django-avatar worked neatly just before django-notification was installed.
What went wrong?
URL notification_notices does not exist. Install django-notification urls, add to urls.py:
url('notification/', include('notification.urls')),
I recommend that you review your installation of django-notification.