Django attribute error: 'module' object has no attribute 'is_usable' - python

I got the following error when calling the url in Django.
It's working before, I guess it's related with some accidental changes I made, but I have no idea what they are.
Thanks before for the help,
Robert
Environment:
Request Method: GET Request URL: http://localhost:8000/time/ Django Version: 1.2 Python Version: 2.6.1 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.admin', 'djlearn.books'] 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 "/Library/Python/2.6/site-packages/django/core/handlers/base.py" in get_response
100. response = callback(request, *callback_args,
**callback_kwargs) File "/Users/rhenru/Workspace/django/djlearn/src/djlearn/../djlearn/views.py" in current_datetime
16. return render_to_response('current_datetime.html',{'current_date':now,}) File "/Library/Python/2.6/site-packages/django/shortcuts/__init__.py" in render_to_response
20. return HttpResponse(loader.render_to_string(*args,
**kwargs), **httpresponse_kwargs) File "/Library/Python/2.6/site-packages/django/template/loader.py" in render_to_string
181. t = get_template(template_name) File "/Library/Python/2.6/site-packages/django/template/loader.py" in get_template
157. template, origin = find_template(template_name) File "/Library/Python/2.6/site-packages/django/template/loader.py" in find_template
128. loader = find_template_loader(loader_name) File "/Library/Python/2.6/site-packages/django/template/loader.py" in find_template_loader
111. if not func.is_usable:
Exception Type: AttributeError at /time/ Exception Value: 'module' object has no attribute 'is_usable'

It looks like Django is looking for a usable template loader, but is finding something in settings.TEMPLATE_LOADERS that isn't honoring the template loader function protocol (described briefly here.)
Is it possible that one of your recent changes was to either settings.TEMPLATE_LOADERS or to a custom template loader? If the latter, your template function needs an is_usable attribute, presumably set to True.

Related

django template errno 13

I have a problem with django template. I made new template file in pycharm and in code i think all is good. But i have errno 13 permission denied. Other templates are working fine.
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/Doggo/2/results/
Django Version: 1.11
Python Version: 3.6.1
Installed Applications:
['Doggo.apps.DoggoConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'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 "C:\Python36-32\lib\site-packages\django\core\handlers\exception.py" in inner
41. response = get_response(request)
File "C:\Python36-32\lib\site-packages\django\core\handlers\base.py" in _get_response
217. response = self.process_exception_by_middleware(e, request)
File "C:\Python36-32\lib\site-packages\django\core\handlers\base.py" in _get_response
215. response = response.render()
File "C:\Python36-32\lib\site-packages\django\template\response.py" in render
107. self.content = self.rendered_content
File "C:\Python36-32\lib\site-packages\django\template\response.py" in rendered_content
82. template = self.resolve_template(self.template_name)
File "C:\Python36-32\lib\site-packages\django\template\response.py" in resolve_template
64. return select_template(template, using=self.using)
File "C:\Python36-32\lib\site-packages\django\template\loader.py" in select_template
48. return engine.get_template(template_name)
File "C:\Python36-32\lib\site-packages\django\template\backends\django.py" in get_template
39. return Template(self.engine.get_template(template_name), self)
File "C:\Python36-32\lib\site-packages\django\template\engine.py" in get_template
162. template, origin = self.find_template(template_name)
File "C:\Python36-32\lib\site-packages\django\template\engine.py" in find_template
136. name, template_dirs=dirs, skip=skip,
File "C:\Python36-32\lib\site-packages\django\template\loaders\base.py" in get_template
38. contents = self.get_contents(origin)
File "C:\Python36-32\lib\site-packages\django\template\loaders\filesystem.py" in get_contents
28. with io.open(origin.name, encoding=self.engine.file_charset) as fp:
Exception Type: PermissionError at /Doggo/2/results/
Exception Value: [Errno 13] Permission denied: 'C:\\Users\\noob1_000\\PycharmProjects\\eWybory\\Doggo\\templates'
i think i have permission to this folder because other templates are working.
I'm working on windows 10
I would recommend to go through this-
Also , the view that you uses the template are also in the same directory as other views since you said that other views are able to access their templates ?
Let me know , if this solves your problem
Maybe you are just forgetting to indicate the template path (template / app/index.html) in the views.py.

django upgrade from 1.9 to 1.10 __init__() got an unexpected keyword argument 'current_app'

ive just upgraded Django from 1.9 to 1.10. i run 1.10 in my test environment and ironed out any upgrade issues to make sure it all worked.
however when ive gone to do it on my live site and gone to load the home page i get the errors below
Environment:
Request Method: GET
Request URL: http://it.local.com/
Django Version: 1.10.5
Python Version: 2.7.5
Installed Applications:
('home.apps.HomeConfig',
'oncall.apps.OncallConfig',
'tools.apps.ToolsConfig',
'sites.apps.SitesConfig',
'maintenance.apps.MaintenanceConfig',
'service.apps.ServiceConfig',
'management.apps.ManagementConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'bootstrap_pagination',
'easy_thumbnails')
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',
'debug_toolbar.middleware.DebugToolbarMiddleware')
Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in _legacy_get_response
249. response = self._get_response(request)
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/www/infternal/home/views.py" in index
13. return render(request, 'home/index.html', {"user": user})
File "/usr/lib/python2.7/site-packages/django/shortcuts/__init__.py" in render
49. context_instance = RequestContext(request, current_app=current_app)
Exception Type: TypeError at /
Exception Value: __init__() got an unexpected keyword argument 'current_app'
It looks like you haven't installed Django 1.10 properly. The line from the traceback context_instance = RequestContext(request, current_app=current_app) does not exist in Django 1.10. I would try uninstalling and reinstalling Django, and then restarting the server.

Attribute error queryset.filter() django

So I got a method in views.py that checks if a certain product is saved in the session variables. If this is the case then it will look up the ID of the product in mongodb in order to filter a queryset on a few attributes of this product. I have the following code:
def moederbordenComp(request,objectlijst):
objectlijst_filtered = objectlijst
if "processorenid" in request.session:
processor= Processoren.objects.get(id=request.session["processorenid"])
objectlijst_filtered = objectlijst.filter(Socket__icontains=processor.Socket)
if "behuizingenid" in request.session:
behuizing = Behuizingen.objects.get(id=request.session["behuizingenid"])
objectlijst_filtered = objectlijst.filter(Form_Factor__icontains=behuizing.Form_Factor)
if "geheugenid" in request.session:
geheugen = Geheugen.objects.get(id=request.session["geheugenid"])
objectlijst_filtered = objectlijst.filter(Geheugentype__icontains=geheugen.Geheugentype)
objectlijst_filtered = objectlijst.filter(Geheugentype__icontains=geheugen.Aantal)
if "hardeid" in request.session:
harde = Harde.objects.get(id=request.session["hardeid"])
objectlijst_filtered = objectlijst.filter(Hardeschijf_bus__icontains=harde.Hardeschijf_bus)
return objectlijst_filtered
So basically. If processorenid exists then filter the queryset called "objectlist" so that only the motherboards remain that contain the processor.Socket.
Now for the real issue:
whenever I remove the objectlijst_filtered and just return the objectlijst (so unfiltered, without doing anything) everything works fine. However if I try to return and then use objectlijst_filtered or even print objectlijst_filtered it raises the following error:'list' object has no attribute 'join'
This is the complete error traceback:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/moederborden/
Django Version: 1.7
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'pcbuilder')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
111. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/robin/Work/School/A-Pc/Website/pcbuilder/views.py" in moederborden
728. moederbordenlijst = compatibility(request,moederbordenlijst)
File "/home/robin/Work/School/A-Pc/Website/pcbuilder/compatibility.py" in compatibility
6. objectlijst_filtered = moederbordenComp(request,objectlijst)
File "/home/robin/Work/School/A-Pc/Website/pcbuilder/compatibility.py" in moederbordenComp
34. print objectlijst_filtered
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/queryset.py" in __repr__
58. self._populate_cache()
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/queryset.py" in _populate_cache
93. self._result_cache.append(self.next())
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py" in next
1137. raw_doc = self._cursor.next()
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py" in _cursor
1182. self._cursor_obj = self._collection.find(self._query,
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/base.py" in _query
1215. self._mongo_query = self._query_obj.to_query(self._document)
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/visitor.py" in to_query
92. query = query.accept(QueryCompilerVisitor(document))
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/visitor.py" in accept
157. return visitor.visit_query(self)
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/visitor.py" in visit_query
80. return transform.query(self.document, **query.query)
File "/usr/local/lib/python2.7/dist-packages/mongoengine/queryset/transform.py" in query
87. value = field.prepare_query_value(op, value)
File "/usr/local/lib/python2.7/dist-packages/mongoengine/fields.py" in prepare_query_value
106. value = re.escape(value)
File "/usr/lib/python2.7/re.py" in escape
214. return pattern[:0].join(s)
Exception Type: AttributeError at /moederborden/
Exception Value: 'list' object has no attribute 'join'
Any help would be greatly appreciated. I've used the filter method in several other parts of the project without any issues so I'm at a loss.
Thanks in advance.

django model with only one CharField is not JSON serializable

I have a very basic 'Place' model:
from django.db import models
class Place(models.Model):
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
and I'm trying to review it using the app: https://github.com/diefenbach/django-reviews
When trying to add a review to certain Place object, in the app's views https://github.com/diefenbach/django-reviews/blob/master/reviews/views.py, it reaches te 'save' method and actually saves a record in the database. However it raises the following TypeError:
Environment:
Request Method: POST
Request URL: http://ec2-54-77-118-44.eu-west-1.compute.amazonaws.com:5000/reviews/add/11/1
Django Version: 1.6.5
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',
'south',
'places',
'reviews')
Installed Middleware:
('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')
Traceback:
File "/home/ubuntu/webapps/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
199. response = middleware_method(request, response)
File "/home/ubuntu/webapps/local/lib/python2.7/site-packages/django/contrib/sessions/middleware.py" in process_response
38. request.session.save()
File "/home/ubuntu/webapps/local/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in save
57. session_data=self.encode(self._get_session(no_load=must_create)),
File "/home/ubuntu/webapps/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in encode
87. serialized = self.serializer().dumps(session_dict)
File "/home/ubuntu/webapps/local/lib/python2.7/site-packages/django/core/signing.py" in dumps
88. return json.dumps(obj, separators=(',', ':')).encode('latin-1')
File "/usr/lib/python2.7/json/__init__.py" in dumps
250. sort_keys=sort_keys, **kw).encode(obj)
File "/usr/lib/python2.7/json/encoder.py" in encode
207. chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py" in iterencode
270. return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py" in default
184. raise TypeError(repr(o) + " is not JSON serializable")
Exception Type: TypeError at /reviews/add/11/1
Exception Value: <Place: Teteria India> is not JSON serializable
I don't understand why this error raises if I'm still not using any AJAX or JSON and as far as I could see neither does the reviews app's views. Does it have anything to do with the forms?
And anyway, how can it be that a model with only one CharField is not JSON serializable? Do I have to provide the serialization?
Thanks!
In the line 148, it store object in the session
request.session["last-rated-object"] = object
then perfoms a redirect to reviews_thank_you's view
def thank_you(request, template_name="reviews/thank_you.html"):
"""Displays a thank you page.
"""
if request.session.has_key("last-rated-object"):
object = request.session.get("last-rated-object")
del request.session["last-rated-object"]
else:
object = None
return render_to_response(template_name, RequestContext(request, {
"object" : object,
}))
It is returning the object without serialize it and i think here is the problem. Can you edit that view to return a serialize version of you object?

django-avatar combined with django-notification gives an error

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.

Categories