I'm using django 1.3.1 and in my application and I have set DEBUG = False in my settings.py. when I refresh the page, the url is going into some loop process and in every loop a slash is being appended to the static files and due to this no static files are being called. I have pasted a sample terminal output below. What could be reason and how can I resolve this?
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg//////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg///////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg/////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg//////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg///////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg////////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg/////////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:30] "GET /static/img/admin/logo.jpg//////////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:31] "GET /static/img/admin/logo.jpg///////////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:31] "GET /static/img/admin/logo.jpg////////////////// HTTP/1.1" 301 0
[30/Mar/2013 11:57:31] "GET /static/img/admin/logo.jpg/////////////////// HTTP/1.1" 301 0
This works fine when I set DEBUG = True in my settings.py.
After a little search, I found this question very helpful. Why does DEBUG=False setting make my django Static Files Access fail?
With debug turned off Django won't handle static files for you any more - your production web server (Apache or something) should take care of that.
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
Related
I am following this tutorial in order to serve React through Django server, but I only get a blank page when I access http://localhost:8000/admin, and I get the following errors on Django local server console:
[20/Jun/2020 17:05:08] "GET /admin HTTP/1.1" 200 2217
[20/Jun/2020 17:05:08] "GET /static/css/main.5f361e03.chunk.css HTTP/1.1" 404 1821
[20/Jun/2020 17:05:08] "GET /static/js/main.853c8ab9.chunk.js HTTP/1.1" 404 1815
[20/Jun/2020 17:05:08] "GET /static/js/2.6d20342a.chunk.js HTTP/1.1" 404 1806
[20/Jun/2020 17:05:08] "GET /static/js/2.6d20342a.chunk.js HTTP/1.1" 404 1806
[20/Jun/2020 17:05:08] "GET /static/js/main.853c8ab9.chunk.js HTTP/1.1" 404 1815
I made all, and only, the changes stated in the tutorial.
EDIT
I have managed to make http://localhost:8000/admin work. I just had to add a coma in TEMPLATES:
TEMPLATES = [
{
# ...
'DIRS': [
os.path.join(BASE_DIR, 'build'),
],
# ...
}
]
But I still get the same error with http://localhost:8000/.
Thanks for your help.
Am getting back the last line after i navigate to the 127.0.0.1:8000/admin
the browser message
This site can’t be reached127.0.0.1 refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
my terminal message
"C:\Program Files\JetBrains\PyCharm 2019.2\bin\runnerw64.exe" C:\Users\UCHE\PycharmProjects\blog\venv\Scripts\python.exe C:/Users/UCHE/PycharmProjects/blog/manage.py runserver 8000
Performing system checks...
Watching for file changes with StatReloader
System check identified no issues (0 silenced).
March 16, 2020 - 22:15:50
Django version 3.0.4, using settings 'blog.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[16/Mar/2020 22:16:26] "GET / HTTP/1.1" 200 19
Not Found: /favicon.ico
[16/Mar/2020 22:16:28] "GET /favicon.ico HTTP/1.1" 404 2136
[16/Mar/2020 22:16:34] "GET /admin/ HTTP/1.1" 302 0
[16/Mar/2020 22:16:34] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1913
[16/Mar/2020 22:16:35] "GET /static/admin/css/base.css HTTP/1.1" 304 0
[16/Mar/2020 22:16:35] "GET /static/admin/css/login.css HTTP/1.1" 304 0
[16/Mar/2020 22:16:35] "GET /static/admin/css/responsive.css HTTP/1.1" 304 0
[16/Mar/2020 22:16:35] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
[16/Mar/2020 22:16:36] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
[16/Mar/2020 22:16:36] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
[16/Mar/2020 22:16:49] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
Process finished with exit code -1
Have you created a super user, ? If you haven't created a super user create one and login to admin of django project.
Use following comand to create a super user
python manage.py createsuperuser
I am continuously getting error while trying to log in to django admin page.
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
December 07, 2019 - 13:53:40
Django version 3.0, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Not Found: /
[07/Dec/2019 13:53:42] "GET / HTTP/1.1" 404 2027
[07/Dec/2019 13:53:47] "GET /admin HTTP/1.1" 301 0
[07/Dec/2019 13:53:47] "GET /admin/ HTTP/1.1" 302 0
[07/Dec/2019 13:53:47] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1913
[07/Dec/2019 13:53:47] "GET /static/admin/css/login.css HTTP/1.1" 200 1233
[07/Dec/2019 13:53:47] "GET /static/admin/css/base.css HTTP/1.1" 200 16378
[07/Dec/2019 13:53:47] "GET /static/admin/css/responsive.css HTTP/1.1" 200 18052
[07/Dec/2019 13:53:47] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[07/Dec/2019 13:53:47] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
[07/Dec/2019 13:53:47] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[07/Dec/2019 13:53:59] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
And after this it is automatically closing.
I used python v3.7 and got this issue. Solved this problem by using 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
302 is not an error. It is a redirect. When you try to visit /admin/ you are redirected to the login page, and then when you have logged in you are redirected to /admin/.
I set SESSION_COOKIE_SECURE = False in settings.py and works.
I have been successfully using django's Authentication backend to authenticate users, and have a modified template system to do this. Everything seemed to work fine. Yesterday, while attempting to publish a production version of my site, I did two modifications:
Changed the LOGIN_REDIRECT_URL from /appointments to /clinic Both of these are two seperate apps in my project.
I added SECURE_SSL_REDIRECT = True to redirect http to https.
After these, I pushed my commit to git development branch. I didnt notice any errors yesterday.
Today I attempted to run the development server, and noticed that I could not login. It was not recognizing my superuser login password. Hence I reset my password by using manage.py changepassword and manage.py passwd. However it still wouldnt login me in. There are no apparent errors shown (Debug is still set to True).
I created a new superuser, but even that login fails. In the frontend I get the error Your username and password didn't match. Please try again..
When trying to login to the admin interface provided by django, I dont get any errors:
$ python3 manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
October 17, 2018 - 16:26:29
Django version 2.1.2, using settings 'myappointments.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[17/Oct/2018 16:26:31] "GET / HTTP/1.1" 302 0
[17/Oct/2018 16:26:31] "GET /accounts/login/?next=/clinic HTTP/1.1" 200 5469
[17/Oct/2018 16:26:31] "GET /appointments/static/clinic/css/bootstrap.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/datepicker.0.6.5.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/jquery-ui/jquery-ui.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/fontawesome.5.2.0.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/fullcalendar.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/jquery-ui/jquery-ui.theme.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/jquery-ui/jquery-ui.structure.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/mytheme.css?dev= HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/registration/css/themedlogin.css HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/css/calcustomcolors.css?dev= HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/jquery-ui/jquery-ui.js?dev= HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/popper.min.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/jquery-3.3.1.min.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/bootstrap.min.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/notify.0.4.2.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/datepicker.0.6.5.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/search.js?dev= HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/lib/moment.min.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/fullcalendar.js HTTP/1.1" 304 0
[17/Oct/2018 16:26:31] "GET /appointments/static/appointments/js/appointment.js?dev= HTTP/1.1" 304 0
[17/Oct/2018 16:26:32] "GET /appointments/static/clinic/icons/health-sign.png HTTP/1.1" 304 0
[17/Oct/2018 16:26:39] "POST /accounts/login/ HTTP/1.1" 302 0
[17/Oct/2018 16:26:39] "GET /clinic HTTP/1.1" 301 0
[17/Oct/2018 16:26:40] "GET /clinic/ HTTP/1.1" 302 0
[17/Oct/2018 16:26:40] "GET /accounts/login/?next=/clinic HTTP/1.1" 200 5469
[17/Oct/2018 16:26:44] "GET /admin/ HTTP/1.1" 302 0
[17/Oct/2018 16:26:44] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1862
[17/Oct/2018 16:26:44] "GET /appointments/static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 8192
[17/Oct/2018 16:26:50] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
[17/Oct/2018 16:26:50] "GET /admin/ HTTP/1.1" 302 0
[17/Oct/2018 16:26:50] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1862
I should probably mention that on my development machine, I use the local python3 version while on production I use a virtualenv.
You probably should have different settings for your production and development environment. Take a look at this structure. Here is a nice article about it. multiple settings
mysite/
|-- mysite/
| |-- __init__.py
| |-- settings/
| | |-- __init__.py
| | |-- base.py
| | |-- ci.py
| | |-- development.py
| | |-- production.py
| | +-- staging.py
| |-- urls.py
| +-- wsgi.py
+-- manage.py
For example you can put SECURE_SSL_REDIRECT = True on production.py file. The idea is to have settings acoording to your environments needs.
I'm using PyInstaller to try and make running of a Django project simple for a user. It works perfectly on my Linux PC but when I try and create it on a Windows PC the static files are not loading and I cannot understand why.
I'm using the following .spec file to create the application.
# -*- mode: python -*-
block_cipher = None
a = Analysis(['manage.py'],
pathex=['C:\\Users\\henry\\potential-waffle'],
binaries=[("C:/Program Files (x86)/Windows Kits/10/Redist/ucrt/DLLs/arm", '.')],
datas=[('media','media'),('potential_waffle/static','static')],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='webscraper',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='webscraper')
My static files are defined within settings.py as:
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "potential_waffle/static"),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
And I'm picking up the static files for runserver:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
The program works fine and does everything it should except the formatting of the browser and within terminal I have the following:
[08/Jun/2018 12:00:57] "GET /login/?next=/ HTTP/1.1" 200 5438
[08/Jun/2018 12:00:57] "GET /static/agency/vendor/bootstrap/css/bootstrap.min.css HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/font-awesome/css/font-awesome.min.css HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/agency/css/agency.css HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/toastr/toastr.min.css HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/js/cookiechoices.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/agency/vendor/jquery/jquery.min.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/agency/vendor/bootstrap/js/bootstrap.min.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/agency/js/jqBootstrapValidation.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/agency/js/contact_me.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/agency/js/agency.min.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/toastr/toastr.min.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/vendor/bootstrap/css/bootstrap.min.css HTTP/1.1" 200 5490
[08/Jun/2018 12:00:57] "GET /login/?next=/static/font-awesome/css/font-awesome.min.css HTTP/1.1" 200 5482
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/css/agency.css HTTP/1.1" 200 5466
[08/Jun/2018 12:00:57] "GET /login/?next=/static/js/cookiechoices.js HTTP/1.1" 200 5464
[08/Jun/2018 12:00:57] "GET /login/?next=/static/toastr/toastr.min.css HTTP/1.1" 200 5466
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/vendor/jquery/jquery.min.js HTTP/1.1" 200 5479
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/vendor/bootstrap/js/bootstrap.min.js HTTP/1.1" 200 5488
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/js/jqBootstrapValidation.js HTTP/1.1" 200 5479
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/js/contact_me.js HTTP/1.1" 200 5468
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/js/agency.min.js HTTP/1.1" 200 5468
[08/Jun/2018 12:00:57] "GET /login/?next=/static/toastr/toastr.min.js HTTP/1.1" 200 5465
The files are in the /static folder (I've checked) but it seems to be redirecting them to a location where the files do not exist (even though we get a 200 response).
I am guessing there is something wrong with the .spec file for Windows but I've tried changing the slashes every which way to no avail. I do get some warning messages during the build (which could be the issue) of the style:
WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:\users\henry\potential-waffle\env\scripts\python.exe