DoesNotExist at /admin/login/ ---- again? - django

I've read the old posts with the same title. But the answers are not for my simple case.... But I need your help to be able to move on.
I just installed django 1.8.1, followed the tutorial to the first time hitting url http://localhost:8000/admin
I did have 'django.contrib.admin' in my settings.py, INSTALLED_APPS list. Beside that, I haven't done anything about admin.
So what's the problem? how to verify my installation? Thanks a lot for your help!
(It's ok for the home page http://localhost:8000)
DoesNotExist at /admin/login/
Site matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/login/?next=/admin/
Django Version: 1.8.1
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/models/query.py in get, line 334
Python Executable: /usr/bin/python
Python Version: 2.7.6
Python Path:
['/home/elim/Projects/python/mydjango',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
Server time: Tue, 30 Jun 2015 20:37:53 +0000

If django.contrib.sites is in your list of installed apps, then you need SITE_ID in your settings file. Adding SITE_ID = 1 to settings.py should do the trick.

Maybe domain name in table django_site not equal your current domain http://localhost:8000.
You need to open dango_site db table and change in first record in field domain value to localhost:8000

I had this issue too and as Mikhail suggested, I had a look in django_site db table, and there was an entry with a domain named example.com.
You could change that record to localhost or 127.0.0.1 as Mikhail said, or you could map example.com domain to 127.0.0.1 in /etc/hosts (as I did) and it will solve the problem. If you choose the latter approach, make sure you access the web interface using http://example.com:8000/admin

Related

i have two projects in django i can not open admin site for my second project,but i can open for my first project,can any one help me

AttributeError at /admin/
'WSGIRequest' object has no attribute 'user'
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/
Django Version: 2.0.2
Exception Type: AttributeError
Exception Value:
'WSGIRequest' object has no attribute 'user'
Exception Location: C:\Users\vaaz\Desktop\venv\lib\site-packages\django\contrib\admin\sites.py in has_permission, line 186
Python Executable: C:\Users\vaaz\Desktop\venv\Scripts\python.exe
Python Version: 3.4.3
Python Path:
['C:\Users\vaaz\website1',
'C:\Windows\system32\python34.zip',
'C:\Users\vaaz\Desktop\venv\DLLs',
'C:\Users\vaaz\Desktop\venv\lib',
'C:\Users\vaaz\Desktop\venv\Scripts',
'C:\Python34\Lib',
'C:\Python34\DLLs',
'C:\Users\vaaz\Desktop\venv',
'C:\Users\vaaz\Desktop\venv\lib\site-packages']
Server time: Mon, 12 Mar 2018 10:21:49 +0000
This looks similar to this post
with your limited error description I can only suggest a few things that were mentioned in the above post:
Older Django versions use MIDDLEWARE_CLASSES = (...) in the settings.py rather than MIDDLEWARE = (...) try changing that variable.
If you are using virtualenv be sure to activate it before trying to runserver
If you created your app in a different version of Django and then installed it on another version it might give you errors.

Wagtail ignoring settings such as ALLOWED_HOSTS

I'm running nginx, gunicorn and wagtail on Ubuntu 16.04. I am not using virtualenv. Both nginx and gunicorn seem to work just fine but when I go to my domain in a browser (let's say myweb.com) I get a disallowed host error.
This seems like a simple problem but I have already added myweb.com as an allowed host in base.py like so: ALLOWED_HOSTS = ['myweb.com']. It even says in the request information that myweb.com is an allowed host in the settings file but it seems like wagtail is just ignoring that. I also tried turning debug off in the dev settings but it still showed me the debug screen.
Edit: The specific error message is (with myweb.com instead of the actual domain):
DisallowedHost at /
Invalid HTTP_HOST header: 'myweb.com'. You may need to add 'myweb.com' to ALLOWED_HOSTS.
Request Method: GET
Request URL: http://myweb.com/
Django Version: 1.11.5
Exception Type: DisallowedHost
Exception Value: Invalid HTTP_HOST header: 'myweb.com'. You may need to add 'myweb.com' to ALLOWED_HOSTS.
Exception Location: /usr/local/lib/python3.5/dist-packages/django/http/request.py in get_host, line 113
Python Executable: /usr/bin/python3
Python Version: 3.5.2
Python Path:
['/home/fixgoats/myweb-root',
'/usr/local/bin',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages']
Traceback:
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py" in inner
41. response = get_response(request)
File "/usr/local/lib/python3.5/dist-packages/django/utils/deprecation.py" in __call__
138. response = self.process_request(request)
File "/usr/local/lib/python3.5/dist-packages/django/middleware/common.py" in process_request
57. host = request.get_host()
File "/usr/local/lib/python3.5/dist-packages/django/http/request.py" in get_host
113. raise DisallowedHost(msg)
Exception Type: DisallowedHost at /
Exception Value: Invalid HTTP_HOST header: 'myweb.com'. You may need to add 'myweb.com' to ALLOWED_HOSTS.
Request Information:
USER [unable to retrieve the current user]
GET No GET data
POST No POST data
FILES No FILES data
Settings Using settings module myweb.settings.dev
ALLOWED_HOSTS 'myweb.com'
There was quite a bit more information on the page but I think this is everything that might be relevant to the problem
Gunicorn needed to be restarted. I don't know if it's supposed to work like this but on my setup it seems like Gunicorn always needs to be restarted to detect changes made to the project files.

Django: Error while installing "Django Registration Redux"

I am trying to install "Django Registration Redux".
I followed every step in the official website to install.
When I am installing django.contrib.sites, the admin doesn't work, and when I comment this the admin starts working but registration does not work in either way.
It gives the error as:
DoesNotExist at /accounts/login/
Site matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8000/accounts/login/
Django Version: 1.9
Exception Type: DoesNotExist
Exception Value:
Site matching query does not exist.
Exception Location: c:\Python27\lib\site-packages\django\db\models\query.py in get, line 387
Python Executable: c:\Python27\python.exe
Python Version: 2.7.11
Python Path:
['E:\\myproject\\mysite',
'C:\\Windows\\SYSTEM32\\python27.zip',
'c:\\Python27\\DLLs',
'c:\\Python27\\lib',
'c:\\Python27\\lib\\plat-win',
'c:\\Python27\\lib\\lib-tk',
'c:\\Python27',
'c:\\Python27\\lib\\site-packages']
Server time: Tue, 24 May 2016 13:26:56 +0000
It sounds like you haven't followed the instructions to enable the sites framework.
After adding django.contrib.sites to INSTALLED_APPS, you need to set SITE_ID = 1 in your settings, then run the migrate command.

ImportError at /admin/ No module named polls_ChoiceField.urls

Django 1.6.2
MacOSX 10.9.2
Python 2.7
I recently deleted a Django App "polls_ChoiceField" which was sitting inside another app "polls" as I was only using it to test a few things. However since i deleted it then the app it was sitting in no longer works.
I deleted the file through the pyDev package explorer. When I synced the Database it gave my the option of deleting the stale content, I selected yes.
Can anyone tell me what I have to do to get the original "polls" all running again?
Relevant Terminal output
localhost:src brendan$ python manage.py syncdb
Creating tables ...
The following content types are stale and need to be deleted:
polls | choice_choicefield
polls | poll_choicefield
Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.
Type 'yes' to continue, or 'no' to cancel: yes
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
I then synced the DB
localhost:src brendan$ python manage.py syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
And I am able to run the server
localhost:src brendan$ python manage.py runserver
Validating models...
0 errors found
When i try to revisit the app in my browser i get
ImportError at /polls/
No module named polls_ChoiceField.urls
Request Method: GET
Request URL: http://localhost:8000/polls/
Django Version: 1.6.2
Exception Type: ImportError
Exception Value:
No module named polls_ChoiceField.urls
Exception Location: /Library/Python/2.7/site-packages/django/utils/importlib.py in import_module, line 40
Python Executable: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.6
Python Path:
['/Users/brendan/Dropbox/workspace/bias_experiment/src',
'/Library/Python/2.7/site-packages/distribute-0.7.3-py2.7.egg',
'/Library/Python/2.7/site-packages/setuptools-2.2-py2.7.egg',
'/Library/Python/2.7/site-packages/pip-1.5.4-py2.7.egg',
'/Library/Python/2.7/site-packages/yolk-0.4.3-py2.7.egg',
'/Library/Python/2.7/site-packages/virtualenv-1.11.4-py2.7.egg',
'/Library/Python/2.7/site-packages/virtualenvwrapper-4.2-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
'/Library/Python/2.7/site-packages']
Server time: Mon, 28 Apr 2014 16:26:46 +0100
Thanks
EDIT:
My urls.py with the bad line of code (the middle url)
urlpatterns = patterns('',
url(r'^polls/', include('polls.urls', namespace="polls")),
url(r'^polls_ChoiceField/', include('polls_ChoiceField.urls', namespace="polls_ChoiceField")),
url(r'^admin/', include(admin.site.urls)),
)
Thanks again.
Check your project-level urls.py, looks like it still tries to use urls from the deleted app.

Django conflict between older example code and new version

My first post here. I have started learning Django over the past week. I have experience with other languages such but am also fairly new to python.
I have been going through this book: http://withdjango.com It has been great so far, however it was written when Django was at version 1.0 if I can tell correctly. However I am using Django 1.6.
I have managed to figure out a few of the small differences between the two here and there, however I am stuck on this one.
I have attempted to follow along with there 'pastebin' exercise (all of the source code is here http://withdjango.com.s3.amazonaws.com/src/pastebin.zip)
One thing I noticed was they used:
from django.views.generic.list_detail import object_list, object_detail
from django.views.generic.create_update import create_object
Where as in 1.6, if I am correct it should be
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
However when I launch this set of code which I have written. I get the following error:
> TypeError at /
> __init__() takes exactly 1 argument (4 given) Request Method: GET Request URL: http://[REMOVED FOR SECURITY] Django
> Version: 1.6.1 Exception Type: TypeError Exception Value:
> __init__() takes exactly 1 argument (4 given) Exception Location: /usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py
> in get_response, line 114 Python Executable: /usr/bin/python Python
> Version: 2.7.3 Python Path: ['/home/phil/pastebin',
> '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2',
> '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',
> '/usr/lib/python2.7/lib-dynload',
> '/usr/local/lib/python2.7/dist-packages',
> '/usr/lib/python2.7/dist-packages', '/usr/lib/pymodules/python2.7']
> Server time: Tue, 21 Jan 2014 03:25:26 +0000
Does anyone have any idea? I should also mention that I have tried using the exact source code the provide online, only changing those changes I mentioned.
Sorry if this is obvious, but I am brand new to all of this. Thank you for any help!
Django 1.0 and latest stable 1.6 have great differences. I advise learning through a more updated book. Particularly Django's own tutorial or Two Scoops of Django have great material (the latter book is going to be updated for 1.6 in near future).