I haven't touched the code on my app in weeks but i'm suddenly getting this exact same TypeError on every page, including Admin pages.
The last thing to happen was an update on a model to change a ForeignKey field, but I don't feel the two are related
Environment:
Request Method: GET
Request URL: http://10.0.0.161:8001/admin/
Django Version: 1.9.3
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',
'phones',
'jobs',
'profiles',
'freelancers',
'stock',
'finance']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'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',
'profiles.middleware.UpdateLastActivityMiddleware']
Traceback:
File "/Users/studioxag/Documents/repos/telephones/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
174. response = self.process_exception_by_middleware(e, request)
File "/Users/studioxag/Documents/repos/telephones/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
172. response = response.render()
File "/Users/studioxag/Documents/repos/telephones/lib/python2.7/site-packages/django/template/response.py" in render
160. self.content = self.rendered_content
File "/Users/studioxag/Documents/repos/telephones/lib/python2.7/site-packages/django/template/response.py" in rendered_content
137. content = template.render(context, self._request)
File "/Users/studioxag/Documents/repos/telephones/lib/python2.7/site-packages/django/template/backends/django.py" in render
95. return self.template.render(context)
File "/Users/studioxag/Documents/repos/telephones/lib/python2.7/site-packages/django/template/base.py" in render
204. with context.bind_template(self):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py" in __enter__
17. return self.gen.next()
File "/Users/studioxag/Documents/repos/telephones/lib/python2.7/site-packages/django/template/context.py" in bind_template
260. updates.update(processor(self.request))
Exception Type: TypeError at /admin/
Exception Value: 'NoneType' object is not iterable
Solved it by looking through some of my own context processors. I had one function that was returning None on a request (after changing an entry and having an empty queryset as a result).
Related
I am facing an error from this Django project. I have tried all the advice i can come across still its not working properly.
Below is the error from the web.
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/login
Django Version: 2.2
Python Version: 3.9.7
Installed Applications:
['main',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_filters']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'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 "C:\Users\INTROVERTED\Downloads\Compressed\FacialRecognitionForPolice-master\venv1\lib\site-packages\django\core\handlers\exception.py" in inner
34. response = get_response(request)
File "C:\Users\INTROVERTED\Downloads\Compressed\FacialRecognitionForPolice-master\venv1\lib\site-packages\django\core\handlers\base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "C:\Users\INTROVERTED\Downloads\Compressed\FacialRecognitionForPolice-master\venv1\lib\site-packages\django\core\handlers\base.py" in _get_response
113.`response = wrapped_callback(request, *callback_args, **callback_kwargs)`
File "C:\Users\INTROVERTED\Downloads\Compressed\FacialRecognitionForPolice-master\FacialRecognitionForPolice-master\main\views.py" in login
171.`hashed = bcrypt.hashpw(request.POST['login_password'], bcrypt.gensalt())`
File "C:\Users\INTROVERTED\Downloads\Compressed\FacialRecognitionForPolice-master\venv1\lib\site-packages\bcrypt\__init__.py" in hashpw
79.`raise TypeError("Strings must be encoded before hashing")`
Exception Type: TypeError at /login
Exception Value: Strings must be encoded before hashing
As error message clearly says, you have to encode the password first.
In main/views.py on line 171 you have
hashed = bcrypt.hashpw(request.POST['login_password'], bcrypt.gensalt())
Your request.POST data is a string, so you should encode it to bytes:
hashed = bcrypt.hashpw(request.POST['login_password'].encode(), bcrypt.gensalt())
You can select other encoding (not default utf8) with .encode('ascii') (choose one and don't change it later, utf8 is probably the best choice in general).
I have an application in django 1.5. I would like to do redirect from one address to another - permanently. That is, I want to get an effect in which I will redirect:
from:
domain.com/team/event-2019/01-03-2019/827
to:
domain.com/team/event/01-03-2019/827 - (without 2019)
traceback:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/team/event/01-03-2019/827
Django Version: 1.5.4
Python Version: 2.7.12
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'haystack',
'users',
'adminextra',
'cms',
'pages',
'files',
'south',
'debug_toolbar',
'home',
'productions',
'contact',
'search')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'translation.middleware.LocaleMiddleware')
Traceback:
File "project/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "project/web/productions/views.py" in activity_details
284. return redirect(activity.get_absolute_url())
File "project/env/local/lib/python2.7/site-packages/django/shortcuts/__init__.py" in redirect
78. return redirect_class(resolve_url(to, *args, **kwargs))
File "project/env/local/lib/python2.7/site-packages/django/shortcuts/__init__.py" in resolve_url
151. return urlresolvers.reverse(to, args=args, kwargs=kwargs)
File "project/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse
496. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "project/env/local/lib/python2.7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
381. raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e))
Exception Type: NoReverseMatch at /team/event/01-03-2019/827
Exception Value: Error importing 'Content-Type: text/html; charset=utf-8
Location: /team/event/01-03-2019/827
': 'HttpResponseRedirect' object has no attribute 'rindex'.
I would like the event to be at the address: always under this url: domain.com/team/event/01-03-2019/827 and redirect on this url from: domain.com/team/event-2019/01-03-2019/827
Now I got an error:
'HttpResponseRedirect' object has no attribute 'find'
from this place:
if event_slug != activity.event.slug or str(date_url) != str(format_date(activity.date, "d-m-Y")):
return HttpResponsePermanentRedirect(activity.get_absolute_url())
I'm trying to add to easy_thumbnails context processors in my settings.py and got the next error:
WSGIRequest' object has no attribute 'mode'
Context processors config:
TEMPLATES = [
{
....
'OPTIONS': {
'context_processors': [
....
'easy_thumbnails.processors.colorspace',
'easy_thumbnails.processors.autocrop',
'filer.thumbnail_processors.scale_and_crop_with_subject_location',
'easy_thumbnails.processors.filters',
],
},
},
]
Traceback:
Environment:
Request Method: GET
Request URL: http://127.0.0.1:10801/uk/
Django Version: 1.8.3
Python Version: 3.4.0
Installed Applications:
('djangocms_admin_style',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'cms',
'adminsortable2',
'treebeard',
'menus',
'sekizai',
'bootstrap3',
'solo',
'mptt',
'modeltranslation',
'easy_thumbnails',
'filer',
'meta',
'meta_mixin',
'djangocms_page_meta',
'djangocms_inherit',
'djangocms_picture',
'djangocms_file',
'djangocms_teaser',
'djangocms_video',
'djangocms_link',
'djangocms_snippet',
'djangocms_text_ckeditor',
'catalog')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.language.LanguageCookieMiddleware')
Traceback:
File "/home/catalog_cms/.env/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
164. response = response.render()
File "/home/catalog_cms/.env/lib/python3.4/site-packages/django/template/response.py" in render
158. self.content = self.rendered_content
File "/home/catalog_cms/.env/lib/python3.4/site-packages/django/template/response.py" in rendered_content
135. content = template.render(context, self._request)
File "/home/catalog_cms/.env/lib/python3.4/site-packages/django/template/backends/django.py" in render
74. return self.template.render(context)
File "/home/catalog_cms/.env/lib/python3.4/site-packages/django/template/base.py" in render
208. with context.bind_template(self):
File "/usr/lib/python3.4/contextlib.py" in __enter__
59. return next(self.gen)
File "/home/catalog_cms/.env/lib/python3.4/site-packages/django/template/context.py" in bind_template
241. updates.update(processor(self.request))
File "/home/catalog_cms/.env/lib/python3.4/site-packages/easy_thumbnails/processors.py" in colorspace
64. if im.mode == 'I':
Exception Type: AttributeError at /uk/
Exception Value: 'WSGIRequest' object has no attribute 'mode'
Yes I'm using latest version of Pillow and easy_thumbnails.
I made a mistake, sorry. This is not context processors, but thumbnail processors. I just add:
THUMBNAIL_PROCESSORS = (
'easy_thumbnails.processors.colorspace',
'easy_thumbnails.processors.autocrop',
'easy_thumbnails.processors.filters',
'filer.thumbnail_processors.scale_and_crop_with_subject_location',
)
Now all working.
I'm trying to verify if a value exists in my database with:
q = model.objects.filter(field__iexact='1')
But this makes an error in Django, which returns this message:
DoesNotExist at /answer_survey/
Model matching query does not exist
This is the entire traceback:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/answer_survey/
Django Version: 1.6.1
Python Version: 2.7.5
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'survey',
'south',
'django_reset',
'chartkick',
'registration')
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 "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/filipeferminiano/Documents/django/panorama/survey/views.py" in answer_survey
265. s = Survey.objects.get(name=cod_survey)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/manager.py" in get
151. return self.get_queryset().get(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/models/query.py" in get
307. self.model._meta.object_name)
Exception Type: DoesNotExist at /answer_survey/
Exception Value: Survey matching query does not exist.
Your error is here:
s = Survey.objects.get(name=cod_survey)
you have't records with name that contains in cod_survey variable...
Add try/except block to catch DoesNotExist exceptions:
try:
s = Survey.objects.get(name=cod_survey)
except Survey.DoesNotExist:
s = 'something else...'
I've installed transifex - django application. Everything looked ok, but if I run:
./manage runserver 8000
I got error message (below). Since I'm inexpedience django user supposedly it is some easy error/mistake. Unfortunately, I'm unable to discover what the problem is.
Any clue will is appreciated!
Thanks, Tomas
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.3.1
Python Version: 2.7.3
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.comments',
'django.contrib.contenttypes',
'django.contrib.flatpages',
'django.contrib.humanize',
'django.contrib.markup',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.sites',
'django.contrib.admindocs',
'staticfiles',
'notification',
'django_filters',
'django_sorting',
'south',
'tagging',
'tagging_autocomplete',
'pagination',
'piston',
'contact_form',
'ajax_select',
'threadedcomments',
'authority',
'haystack',
'social_auth',
'userena',
'guardian',
'easy_thumbnails',
'djcelery',
'djkombu',
'compressor',
'transifex.txcommon',
'transifex.languages',
'transifex.projects',
'transifex.releases',
'transifex.actionlog',
'transifex.txpermissions',
'transifex.teams',
'transifex.resources',
'django_addons',
'autofetch',
'charts',
'cla',
'copyright',
'datastores',
'gtranslate',
'helptext',
'jsonmap',
'locks',
'lotte',
'priorities',
'suggestions',
'timeline',
'trans_memory',
'txapps',
'txcron',
'txtestsuite',
'watches',
'webhooks',
'widgets']
Installed Middleware:
['django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django_sorting.middleware.SortingMiddleware',
'pagination.middleware.PaginationMiddleware',
'userena.middleware.UserenaLocaleMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware']
Traceback:
File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/core/handlers /base.py" in get_response
101. request.path_info)
File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/core/urlresolvers.py" in resolve
252. sub_match = pattern.resolve(new_path)
File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django /core/urlresolvers.py" in resolve
252. sub_match = pattern.resolve(new_path)
File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/core/urlresolvers.py" in resolve
250. for pattern in self.url_patterns:
File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/core/urlresolvers.py" in _get_url_patterns
279. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django /core/urlresolvers.py" in _get_urlconf_module
274. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/utils/importlib.py" in import_module
35. __import__(name)
File "/usr/lib/python2.7/site-packages/transifex-1.3.0devel-py2.7.egg/transifex/addons/cla/urls.py" in <module>
2. from transifex.projects.urls import PROJECT_URL
File "/usr/lib/python2.7/site-packages/transifex-1.3.0devel-py2.7.egg/transifex/projects/urls/__init__.py" in <module>
6. from transifex.projects.feeds import LatestProjects, ProjectFeed, ProjectTimelineFeed
File "/usr/lib/python2.7/site-packages/transifex-1.3.0devel-py2.7.egg/transifex/projects/feeds.py" in <module>
11. current_site = Site.objects.get_current()
File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/contrib/sites/models.py" in get_current
25. current_site = self.get(pk=sid)
File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/models/manager.py" in get
132. return self.get_query_set().get(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/Django-1.3.1-py2.7.egg/django/db/models/query.py" in get
349. % self.model._meta.object_name)
Exception Type: DoesNotExist at /
Exception Value: Site matching query does not exist.
First of all run python manage.py syncdb. Then check this query in django shell:
Site.objects.get(id=1)
if DoesNotExist error is raised create Site object manually:
Site.objects.create(name='example.com', domain='example.com')