gunicorn Serve Error(500) in django 3.2 app on localhost - django

I'm trying to serve my Django 3.2 application using gunicorn on my localhost. First time, it ran correctly. Later, I changed DEBUG parameter to False in settings.py and I run it again. This time it gives me a server error. In terminal there is no error. See the pictures below. Why is this happening ? How to fix this ?
Error Page
settings.py
terminal

As you are trying to use it in your localhost you need to change the DEBUG = True instead of DEBUG = False and It will work smoothly

Related

Seeing Django debug 404 page despite having DEBUG = False

I have been following this tutorial along to deploy my first Django site and have successfully reached the section 'Configure Nginx to Proxy Pass to Gunicorn' which all seems to be working.
My problem is that, despite my settings.py file containing the following:
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
I am still getting Django's debug=true 404 page with the following error:
"You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page."
I changed the file to DEBUG = False after completing the 'Configure Nginx to Proxy Pass to Gunicorn' step in the tutorial by pulling the change from my GitHub repository. Am I missing an additional step with Nginx in order to turn debug off and serve a standard 404 page?
Edit: It actually seems that any adjustments I make to the settings.py file in my repository, when pulled on to the server, don't have any effect. I commented out the whole settings.py file to see if it would break the webpage; nothing happened.
I'm guess that you does't restart web server after code editing. Try to restart your Gunicorn server, when you work with django runserver command it automatically restart web server on any change in code. Gunicorn dont do this by default, if you wanted that Gunicorn also restart server automatically, run it with --reload argument. But it dose not recommended into production

Django won't start on apache webserver

I'm trying to run my django project with an apache webserver.
I get the following error:
Errors : The included urlconf hastahane.urls doesn't have any patterns in it`
If I'm running my project with the django development server there isn't any error.
Do you have an idea?
You should check that the DEBUG settings is set to False and that you have properly filled the ALLOWED_HOSTS list (see the docs).
Also, are you using the django-debug-toolbar? In that case that may be the cause of the error. Check this answer.

Why does setting debug to false in django settings stop Heroku app from loading in development and production?

In my settings i have set DEBUG=False but this instead generated a 500 Error in both dev and production. so i looked around and came across this (Setting DEBUG = False causes 500 Error) and tried it out.
ALLOWED_HOSTS = ['www.heroku.com']
But this did not work, what am i not doing right? Am hosting with heroku
Your app is not hosted on www.heroku.com. Instead, try
ALLOWED_HOSTS = [".herokuapp.com"]
did you try
python manage.py collecstatic
?
you should review files directory becuase in prodhuction static files directory changes. heroku uses whitenouse

Running Gunicorn with Foreman

If I do runserver or gunicorn straight from the commandline, the website works fine. However, if I try to run gunicorn using Foreman as specified in the Heroku documentation:
web: gunicorn myapp.wsgi
Then my website's static files are suddenly inaccessible; trying to go to
http://0.0.0.0:5000/static/js/jquery-1.9.1.min.js
Only gives me this error message:
Using the URLconf defined in myapp.urls, Django tried these URL patterns, in this order:
^$ [name='homepage']
...
The current URL, static/js/jquery-1.9.1.min.js, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
As I've said, the static files are definitely accessible if calling gunicorn or runserver directly, or even if using runserver with foreman start, so I'm guessing it doesn't have too much to do with my static files settings?
Also, running gunicorn on foreman with DEBUG = False doesn't even return anything except for a 500 error. Nothing is logged, not even on Sentry, so I have no idea what's wrong. It also works fine using gunicorn or runserver alone, or using runserver with foreman.
Any ideas what I can do to fix this problem?
Don't know about why the static files were not being retrieved, but the DEBUG = False 500 error was simply caused by my ALLOWED_HOSTS setting, and fixing that produced no further issues.
I would try to print out settings while running under gunicorn and see if your media URL is correct and js files are indeed accessible.
As for 500 error it is probably trying to show you 404 page, but you do not have a template for it, so it raises 500, and old django quirk ;)
PS. This all is assuming that you verified that you have correct URL pattern in that error

Django: Why can't I get my development server to work?

I'm on Windows XP with the latest install of Python 2.6 (and the development server has been working up until last night). I have the path and Python path stuff all set up, and my dev server has worked forever. I recently replaced my django-trunk with a new pull from the Django trunk. I thought maybe there was an import error or something that Django wouldn't catch in one of my app's models.py so I started a new project (empty but just for testing) and it still didn't work. I restarted my computer and tried the new empty app again python manage.py runserver 8080 and went to http://127.0.0.1:8080/ and it worked ("Congrats. Django is insta..."). So I CD over to my real project and tried again and it didn't work. I'm not getting a stack trace or anything like that. I either get [17/Ja/2010 16:30:51] "GET / HTTP/1.1" 301 0 as output when I visit http://127.0.0.1:8080/ in my CMD prompt or I get nothing (even if I hard refresh, etc). What could this be?
Update (Important):
Firefox tells me Firefox can't find the server at www.127.0.0.1. even though I'm at http://127.0.0.1:8080/. Does this mean that Django is really sending a 301 to www.127.0.0.1 for some other reason?
I removed PREPEND_WWW from settings.py, and even removed all the apps (except for the django admin and preset ones) that were installed in settings.py.
Update 2: It works in Safari! How can this be? It's like Firefox is getting some sort of 301 but Safari works just fine.
yep, 301 permanent redirect is remembered by firefox, i've been stuck once on that one, restarting or cleaning history/cache didn't help, so i just ran it on another port.
edit after commenting:
assuming you use some localhost_settings.py to setup your project locally and still want to www_redirect on the production website:
try:
from localhost_settings import *
PREPEND_WWW = False
except ImportError:
PREPEND_WWW = True
i do it this way