I am working on Django admin creation using "python manage.py createsuperuser" in the shell.I created username,email and password and then ran the server using "python manage.py runserver" in the terminal of PyCharm. What I got is:
(venv) H:\django project\mysite1>python manage.py createsuperuser
Username (leave blank to use 'maitreya'): mtr007
Email address: maitreya#gmail.com
Password:
Password (again):
Superuser created successfully.
AND AFTER THIS I RAN THE SERVER
(venv) H:\django project\mysite1>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
April 26, 2020 - 11:32:06
Django version 3.0.5, using settings 'mysite1.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Not Found: /
[26/Apr/2020 11:32:08] "GET / HTTP/1.1" 404 2028
[26/Apr/2020 11:32:13] "GET /admin/ HTTP/1.1" 302 0
[26/Apr/2020 11:32:13] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1913
[26/Apr/2020 11:32:27] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
Now What happens is that the web page has created a Django administration login and accepting my username and password but suddenly the site stops working.
I am posting a screenshot of the site.
Can someone address and solve what should I do(should install some module or verify the path etc.) or look for new versions of some django documentations.
Related
I'm new to python and django.
I've copied my production app, that another developer wrote, onto my local. It's working perfectly. When I run django admin I get the login form. But when I enter my ID and PW I get redirected to the same login form, only it's blank; I never get logged in.
The server console reads:
[26/Apr/2022 06:25:21] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
[26/Apr/2022 06:25:21] "GET /admin/ HTTP/1.1" 302 0
[26/Apr/2022 06:25:21] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 11020
I don't understand what's needed to change or get added. Any help appreciated.
I've sorted the issue.
I commented out SESSION_COOKIE_DOMAIN from my settings.py file and that solved it.
I upgraded Django from 2.2 to 3.0, Now I can't access admin page.
Every time I access http://127.0.0.1:8000/admin the dev. server quits without any message or error.
If I revert back to Django 2.2 everything works fine.
I did fresh virtualenv and created new project unfortunately, I hit the same wall again the Dev. server quits without any error.
Is this a common issue or do I have any error?
I am using windows 10 64-bit and Pycharm community 2019.2.5
my virtual is:
Package Version
------------------- ----------
asgiref==3.2.3
certifi==2019.11.28
chardet==3.0.4
Django==3.0
djangorestframework==3.10.3
idna==2.8
Pillow==6.2.1
pip==19.3.1
PyJWT==1.7.1
pytz==2019.3
requests==2.22.0
setuptools==42.0.2
six==1.13.0
sqlparse==0.3.0
twilio==6.34.0
urllib3==1.25.7
wheel==0.33.6
Stack trace
System check identified no issues (0 silenced).
December 06, 2019 - 21:59:45
Django version 3.0, using settings 'suhul_prj.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[06/Dec/2019 21:59:56] "GET / HTTP/1.1" 200 16351
[06/Dec/2019 21:59:56] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[06/Dec/2019 21:59:56] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[06/Dec/2019 21:59:56] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
[06/Dec/2019 21:59:56] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
[06/Dec/2019 22:00:02] "GET /admin HTTP/1.1" 301 0
[06/Dec/2019 22:00:02] "GET /admin/ HTTP/1.1" 302 0
[06/Dec/2019 22:00:02] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1913
[06/Dec/2019 22:00:03] "GET /static/admin/css/base.css HTTP/1.1" 200 16378
[06/Dec/2019 22:00:03] "GET /static/admin/css/login.css HTTP/1.1" 200 1233
[06/Dec/2019 22:00:03] "GET /static/admin/css/responsive.css HTTP/1.1" 200 18052
[06/Dec/2019 22:00:08] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
(home_venv) C:\Users\Admin\Dropbox\django_projects\suhul_prj>
looks like this problem going back to python and Django versions incompatibility, which caused WSGI segmentation fault, I had the same issue while I was using python 3.7 and with downgrading python to 3.6 it has been solved!
Just want to share my experience solving the same issue.
I used python v3.7 and got this issue. Solved this problem by upgrading to python v3.8 and creating a new venv.
Now my python version FYI:
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Also another post mentioned this issue.
I installed a Mezzanine CMS by default and I will try to serve by gunicorn
-- With python manage.py runserver, all static files are served only if DEBUG = True
Logs said:
... (DEBUG=False)
[07/Sep/2018 12:23:56] "GET /static/css/bootstrap.css HTTP/1.1" 301 0
[07/Sep/2018 12:23:57] "GET /static/css/bootstrap.css/ HTTP/1.1" 404 6165
...
-- With gunicorn helloworld.wsgi --bind 127.0.0.1:8000, no static found!
Logs said:
$ gunicorn helloworld.wsgi --bind 127.0.0.1:8000
[2018-09-07 14:03:56 +0200] [15999] [INFO] Starting gunicorn 19.9.0
[2018-09-07 14:03:56 +0200] [15999] [INFO] Listening at: http://127.0.0.1:8000 (15999)
[2018-09-07 14:03:56 +0200] [15999] [INFO] Using worker: sync
[2018-09-07 14:03:56 +0200] [16017] [INFO] Booting worker with pid: 16017
Not Found: /static/css/bootstrap.css/
Not Found: /static/css/mezzanine.css/
Not Found: /static/css/bootstrap-theme.css/
Not Found: /static/mezzanine/js/jquery-1.8.3.min.js/
Not Found: /static/js/bootstrap.js/
Not Found: /static/js/bootstrap-extras.js/
Please have a look to url wanted: gunicorn or mezzanine (or else?) add a / character in the end of url.
I did this command too python manage.py collectstatic with no effect :(
STATIC_ROOT is correct and I applied https://docs.djangoproject.com/en/1.10/howto/static-files/#serving-static-files-during-development
Do you have a tips or solution? I'm afraid I didn't search correctly!
Thanks
Momo
It's Ok for me, thanks!
A correct search found me the answers
-- for internal server DEBUG=False will not serve static files, it's a job for webserver (nginx, apache) : Why does DEBUG=False setting make my django Static Files Access fail?
If you still need to server static locally (e.g. for testing without debug) you can run devserver in insecure mode:
manage.py runserver --insecure
-- for gunicorn webserver, we need add static manually in urls.py : How to make Django serve static files with Gunicorn?
in urls.py, add this:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# ... the rest of your URLconf goes here ...
urlpatterns += staticfiles_urlpatterns()
More info here
well done!
I am curious, I run the runserver with Django, the first request is what I am working on, but how about the others? I don't provide baidu server, why does someboy request it from my temporary server?
[02/Feb/2018 12:20:05] "GET /stk/?format=json&_=1517542783567
HTTP/1.1" 200 2247 Invalid HTTP_HOST header: '1.164.39.192'. You may
need to add u'1.164.39.192' to ALLOWED_HOSTS. [02/Feb/2018 12:50:54]
"GET //wp-login.php HTTP/1.1" 400 62538 Invalid HTTP_HOST header:
'1.164.39.192'. You may need to add u'1.164.39.192' to ALLOWED_HOSTS.
[02/Feb/2018 12:51:20] "GET /wp//wp-login.php HTTP/1.1" 400 62571
Invalid HTTP_HOST header: 'www.baidu.com'. You may need to add
u'www.baidu.com' to ALLOWED_HOSTS. [02/Feb/2018 14:15:00] "GET
http://www.baidu.com/cache/global/img/gs.gif HTTP/1.1" 400 62677
if a request comes(like search engine crawlers etc.) with the HTTP host header which is not present in your ALLOWED_HOSTS setting Django create log like yours.
Before they hit Django app you can kill these request. For solutions check this
Recently, I've started to experience an issue on my Django-based site where logins will fail with no errors reported to the user after a few days of site uptime. Already logged in sessions continue to work fine, but no new logins can happen.
The relevant info:
I'm using the normal django.contrib.auth authentication stuff
I am using PostgreSQL for the DB via the django.db.backends.postgresql_psycopg2 backend
I am running on OSX 10.6.7 with Python 2.6.1 and Django 1.3
Django is running in FastCGI mode behind nginx
My gut feeling is that there is something breaking down in the connection / socket to the DB at some point, because if I kill Django and restart it, everything works just fine again (i.e. the DB itself is definitely not overloaded and can be accessed just fine using the psql commandline tool).
Unfortunately, there is nothing in the logs about the error (well, at least nothing is being emitted via the normal Python logging module which is how I trap all my logs) and there are no errors reported to the web browser. All the client sees is that they get sent back to the login page again, as if they had just refreshed their browser.
Any help much appreciated.
Not sure if it's relevant, but my middleware classes are:
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
UPDATE
After looking into the nginx access logs, I can see that the login actually works briefly then suddenly doesn't work:
"POST /accounts/login/ HTTP/1.1" 302 5 "https://myapp.com/accounts/login/?next=/orders"
"GET /orders HTTP/1.1" 301 185 "-"
"GET /orders HTTP/1.1" 302 5 "-"
"GET /accounts/login/?next=/orders HTTP/1.1" 301 185 "-"
"GET /accounts/login/?next=/orders HTTP/1.1" 200 1297 "-"
As you can see, the login works and the client is redirected to the 'next' URL (/orders), but then the third line redirects (302) the client back out to the login page, presumably because the #login_required decorator (which is applied to the /orders controller) determined that they weren't really logged in.
For comparison, this is a successful login sequence:
"POST /accounts/login/ HTTP/1.1" 302 5 "https://myapp.com/accounts/login/?next=/orders"
"GET /orders HTTP/1.1" 301 185 "-"
"GET /orders HTTP/1.1" 200 59364 "-"
And a login with the wrong password (the POST comes back with a 200 instead of a 302):
"POST /accounts/login/ HTTP/1.1" 200 1426 "https://myapp.com/accounts/login/?next=/orders"
The difference between a normal login and the broken one is that the client gets a 200 OK for /orders instead of 302 back to the login page. I have no idea how the auth middleware can allow the login and then kick the user back out immediately after. Is there a possible race condition here where the login controller hasn't been able to persist the logged-in state into the DB in time for the /orders controller to see it and allow the user to stay logged in?
Also - I have noticed that a Django restart isn't necessarily required to fix the issue - sometimes the server just miraculously starts letting clients log in again.
Sounds like your web server is using persistent connections and running out. What do the pg logs say when you can't log in?