Django admin/ ViewDoesNotExist - python

I checked the other questions on here like this one, but couldn't get an accurate answer that would solve my problem. When i run the dev server with python manage.py runserver I get the following `
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 1.6.4
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',
'firstapp')
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/Python/2.7/site-packages/Django-1.6.4-py2.7.egg/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/Django-1.6.4-py2.7.egg/django/contrib/admin/sites.py" in wrapper
215. return self.admin_view(view, cacheable)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/Django-1.6.4-py2.7.egg/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/Django-1.6.4-py2.7.egg/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/Django-1.6.4-py2.7.egg/django/contrib/admin/sites.py" in inner
194. current_app=self.name):
File "/Library/Python/2.7/site-packages/Django-1.6.4-py2.7.egg/django/core/urlresolvers.py" in reverse
503. app_list = resolver.app_dict[ns]
File "/Library/Python/2.7/site-packages/Django-1.6.4-py2.7.egg/django/core/urlresolvers.py" in app_dict
329. self._populate()
File "/Library/Python/2.7/site-packages/Django-1.6.4-py2.7.egg/django/core/urlresolvers.py" in _populate
303. lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
File "/Library/Python/2.7/site-packages/Django-1.6.4-py2.7.egg/django/core/urlresolvers.py" in callback
230. self._callback = get_callable(self._callback_str)
File "/Library/Python/2.7/site-packages/Django-1.6.4-py2.7.egg/django/utils/functional.py" in wrapper
32. result = func(*args)
File "/Library/Python/2.7/site-packages/Django-1.6.4-py2.7.egg/django/core/urlresolvers.py" in get_callable
118. (lookup_view, mod_name))
Exception Type: ViewDoesNotExist at /admin/
Exception Value: Could not import Chinatown.views. View does not exist in module Chinatown.
`
But when i check my other project with which i follow the official django tut I dont have the mentioned views file in the project directory but I am able to see the admin page. Any suggestions why is the error being raised?

i think it will be more useful if just copy / paste error log . use:
./manage.py runserver --traceback
you need to add function in chinatown/views.py say "food"
and a url pattern in project's urls.py:
from django.conf.urls import url
urlpatterns = [
url(r'^food/$', 'chinatown.views.food'),
]
https://docs.djangoproject.com/en/dev/topics/http/urls/

Related

Django Allauth TypeError at /accounts/confirm-email/

I'm using django-allauth for my django authentication and
while confirming the email i get
TypeError at /accounts/confirmemail/MQ:1mk57U:HtWDA8B5NClWhK2L6nDxJgwlNRGItW_4FyhDqcbcfow/ and it's complaining about argument of type 'bool' is not iterable
as I searched answers were in the cause of using django-rest-allauth and here I'm not using any rest api and facing this issue.
some configs on my settings.py file
# all auth config
AUTHENTICATION_BACKENDS = [
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
# `allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend",
]
SITE_ID = 1
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
ACCOUNT_AUTHENTICATION_METHOD = "username_email"
ACCOUNT_LOGIN_ON_PASSWORD_RESET = True
Update: The full error tracback looks
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/confirm-email/MQ:1mk57U:HtWDA8B5NClWhK2L6nDxJgwlNRGItW_4FyhDqcbcfow/
Django Version: 3.2.9
Python Version: 3.9.7
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.twitter',
'allauth.socialaccount.providers.telegram',
'allauth.socialaccount.providers.instagram',
'django_extensions',
'avatar',
'django_cleanup.apps.CleanupConfig',
'user']
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 (most recent call last):
File "/home/ali/.local/lib/python3.9/site-packages/django/shortcuts.py", line 130, in resolve_url
return reverse(to, args=args, kwargs=kwargs)
File "/home/ali/.local/lib/python3.9/site-packages/django/urls/base.py", line 86, in reverse
return resolver._reverse_with_prefix(view, prefix, *args, **kwargs)
File "/home/ali/.local/lib/python3.9/site-packages/django/urls/resolvers.py", line 694, in _reverse_with_prefix
raise NoReverseMatch(msg)
During handling of the above exception (Reverse for 'True' not found. 'True' is not a valid view function or pattern name.), another exception occurred:
File "/home/ali/.local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/ali/.local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/ali/.local/lib/python3.9/site-packages/django/views/generic/base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "/home/ali/.local/lib/python3.9/site-packages/django/views/generic/base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "/home/ali/.local/lib/python3.9/site-packages/allauth/account/views.py", line 295, in get
return self.post(*args, **kwargs)
File "/home/ali/.local/lib/python3.9/site-packages/allauth/account/views.py", line 334, in post
return redirect(redirect_url)
File "/home/ali/.local/lib/python3.9/site-packages/django/shortcuts.py", line 41, in redirect
return redirect_class(resolve_url(to, *args, **kwargs))
File "/home/ali/.local/lib/python3.9/site-packages/django/shortcuts.py", line 136, in resolve_url
if '/' not in to and '.' not in to:
Exception Type: TypeError at /accounts/confirm-email/MQ:1mk57U:HtWDA8B5NClWhK2L6nDxJgwlNRGItW_4FyhDqcbcfow/
Exception Value: argument of type 'bool' is not iterable
The proplem come from after email confirmation done the reverse url is not valid so you need to go to your setting and check setting for that you must give it valid url to be redircted after confirmation
So I hope to revise the urls

Django - 'User' object has no attribute 'session_set'

I want to add a Sessions tabs to my Django project:
navbar.html
<li>Sessions</li>
But i keep getting the following error:
'User' object has no attribute 'session_set''User' object has no attribute 'session_set'
Exception Location: C:\Users\User\lib\site-packages\django\utils\functional.py in inner, line 214
I don't know where this error comes from, i did not find any other reference online, can anyone help me?
Here is the login view that i'm using: https://github.com/Bouke/django-two-factor-auth/blob/master/two_factor/views/core.py
Full traceback
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/account/sessions/
Django Version: 2.1.7
Python Version: 3.7.0
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main.apps.MainConfig',
'tinymce',
'captcha',
'django.contrib.sites',
'django_otp',
'django_otp.plugins.otp_static',
'django_otp.plugins.otp_totp',
'two_factor']
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',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django_otp.middleware.OTPMiddleware']
Traceback:
File "C:\Users\User\lib\site-packages\django\core\handlers\exception.py" in inner
34. response = get_response(request)
File "C:\Users\User\lib\site-packages\django\core\handlers\base.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)
File "C:\Users\User\lib\site-packages\django\core\handlers\base.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\User\lib\site-packages\django\views\generic\base.py" in view
68. return self.dispatch(request, *args, **kwargs)
File "C:\Users\User\lib\site-packages\django\utils\decorators.py" in _wrapper
45. return bound_method(*args, **kwargs)
File "C:\Users\User\lib\site-packages\django\contrib\auth\decorators.py" in _wrapped_view
21. return view_func(request, *args, **kwargs)
File "C:\Users\User\lib\site-packages\user_sessions\views.py" in dispatch
22. **kwargs)
File "C:\Users\User\lib\site-packages\django\views\generic\base.py" in dispatch
88. return handler(request, *args, **kwargs)
File "C:\Users\User\lib\site-packages\django\views\generic\list.py" in get
142. self.object_list = self.get_queryset()
File "C:\Users\User\lib\site-packages\user_sessions\views.py" in get_queryset
14. return self.request.user.session_set\
File "C:\Users\User\lib\site-packages\django\utils\functional.py" in inner
214. return func(self._wrapped, *args)
File "C:\Users\User\lib\site-packages\django\utils\functional.py" in inner
214. return func(self._wrapped, *args)
Exception Type: AttributeError at /account/sessions/
Exception Value: 'User' object has no attribute 'session_set'
You need to replace django.contrib.sessions in your INSTALLED_APPS with user_sessions if you want to use django-user-sessions. This will setup its models correctly.
Furthermore make sure you have also followed all other installation instructions.

Reverse for '' not found. '' is not a valid view function or pattern name

I'm trying to add or remove a row into DB, using a button click that redirects back to the same page,, here are my files
views.py
def favorite_item (request, pk):
favitem = get_object_or_404(Item, pk=pk)
userfav = Favorite.objects.filter(user=request.user)
for items in userfav:
if items.item == favitem:
items.delete()
else:
items = Favorite(item=favitem, user=request.user)
items .save()
return redirect('')
urls.py
path('<int:pk>/favorite_item/', views.favorite_item, name='favorite_item'),
html
<a href="{% url 'favorite_item' dress.id %}">
<img src="{% static 'img/gold_star.png' %}"></a>
but whenever I click it I get the error :
error
Reverse for '' not found. '' is not a valid view function or pattern name.
Entire Traceback
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/3/favorite_item/
Django Version: 2.0.5
Python Version: 3.6.5
Installed Applications:
['django_filters',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'fostania_web_app.apps.FostaniaWebAppConfig']
Installed Middleware:
('whitenoise.middleware.WhiteNoiseMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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\LiTo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py" in inner
35. response = get_response(request)
File "C:\Users\LiTo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)
File "C:\Users\LiTo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "F:\django\fostania\fostania_web_app\views.py" in favorite_item
278. return redirect('')
File "C:\Users\LiTo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\shortcuts.py" in redirect
58. return redirect_class(resolve_url(to, *args, **kwargs))
File "C:\Users\LiTo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\shortcuts.py" in resolve_url
149. return reverse(to, args=args, kwargs=kwargs)
File "C:\Users\LiTo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\base.py" in reverse
88. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "C:\Users\LiTo\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\urls\resolvers.py" in _reverse_with_prefix
632. raise NoReverseMatch(msg)
Exception Type: NoReverseMatch at /3/favorite_item/
Exception Value: Reverse for '' not found. '' is not a valid view function or pattern name.
Thank you for adding the traceback. Its the redirect call. So when you use the redirect shortcut method the string you give it needs to match the name variable in at least one of your configured paths. So when I tried to redirect to nothing in my project with:
return redirect("")
I get the exact same error because I have no paths configured for that:
urlpatterns = [
path('<int:key>/authors/', views.get_authors, name='authors'),
path('home/', views.home, name='home')
]
But when i changed my path for home to use the name ="":
urlpatterns = [
path('<int:key>/authors/', views.get_authors, name='authors'),
path('home/', views.home, name='')
]
viola, redirects to home.

Django TypeError on every page

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).

Django error 'too many values to unpack' in objects.get(id)

I have url like this http://gagandeepdesk/2690/ which I am filtering with urls.py file and sending 2690 as one of the parameters to the function.
my urls.py filter looks like this,
url(r'^(\d+)/', 'scango.scanner.views.download'),
And that function looks like this,
def download(request, MediaId):
media = Media.objects.get(id=int(MediaId))
#print media
return HttpResponse(FileIterWrapper(open(media.path)))
I am getting error 'too many values to unpack' on line
media = Media.objects.get(id=int(MediaId))
I also tried running this function standalone without request object and it is running perfectly fine. So, I am confused what I have done wrong here.
Environment:
Request Method: GET
Request URL: http://gagandeepdesk/2690/
Django Version: 1.3
Python Version: 2.7.1
Installed Applications:
['haystack',
'scanner',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin']
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:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "C:\Users\gagasing\Desktop\ideas\scango\..\scango\scanner\views.py" in download
21. media = Media.objects.get(id=int(MediaId))
File "C:\Python27\lib\site-packages\django\db\models\manager.py" in get
132. return self.get_query_set().get(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in get
343. clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in filter
552. return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py" in _filter_or_exclude
570. clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in add_q
1170. can_reuse=used_aliases, force_having=force_having)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py" in add_filter
1013. arg, value = filter_expr
Exception Type: ValueError at /2690/
Exception Value: too many values to unpack
(r'^(?P<MediaId>\d+)/$', 'scango.scanner.views.download')
Maybe try this instead?
This is an example of named groups.
In Python regular expressions, the syntax for named regular expression
groups is (?Ppattern), where name is the name of the group and
pattern is some pattern to match.

Categories

Resources