Why get "Server Error 500" instead of 404 template?

96 views
Skip to first unread message

Chris Seberino

unread,
Dec 10, 2017, 11:42:56 AM12/10/17
to Django users
I cannot track down why 404 page isn't being used.  I can't get any help from syslog or Nginx log files.
I tried adding DEBUG=True to settings.py and still no clues.
I only get "Server Error 500".

Here is settings.py

TEMPLATES        = [{"BACKEND" :
                        "django.template.backends.django.DjangoTemplates",
                     "DIRS"    : [VIEWS.format(e) for e in APPS],
                     "OPTIONS" :
                        {"context_processors" :
                         ["django.template.context_processors.debug",
                          "django.template.context_processors.request"]}}]
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"]
WSGI_APPLICATION = "nginx.wsgi.application"
INSTALLED_APPS   = APPS + ["django.contrib.admin",
                           "django.contrib.auth",
                           "django.contrib.contenttypes",
                           "django.contrib.messages",
                           "django.contrib.sessions",
                           "django.contrib.staticfiles"]

Antonis Christofides

unread,
Dec 11, 2017, 8:20:14 AM12/11/17
to django...@googlegroups.com

Hello,

Usually when you get a mere "Server error 500" without it showing you the Debug page though you have DEBUG=True, this means that the error occurs very early, before Django has had the opportunity to run. In that case, the error should have been logged in the gunicorn/uwsgi/whatever log, i.e. in whatever program it is that runs Django.

For more information, you need to show us your nginx configuration and your wsgi server configuration.

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/977652c4-f86e-491c-a5af-ccbba38dc733%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chris Seberino

unread,
Dec 11, 2017, 9:45:04 AM12/11/17
to Django users


For more information, you need to show us your nginx configuration and your wsgi server configuration.



Thanks a million.  Here is what you asked for...


---------------------------------------------------------------------------------------------------------------------------
 % more wsgi.py 

import django.core.wsgi
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
application = django.core.wsgi.get_wsgi_application()


---------------------------------------------------------------------------------------------------------------------------
% more nginx.conf

server {
        server_name         ~^(www\.)?domainname\.(org|com)$;
        listen              80;
        return              301 https://domainname.org$request_uri;
}

server {
        server_name         ~^(www\.)?domainname\.com$;
        listen              443 ssl http2;
        ssl_certificate     /etc/letsencrypt/live/domainname.org/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domainname.org/privkey.pem;
        return              301 https://domainname.org$request_uri;
}

server {
        server_name         ~^(www\.)?domainname.org$;
        listen              443 ssl http2;
        ssl_certificate     /etc/letsencrypt/live/domainname.org/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/domainname.org/privkey.pem;
        root                /home/cs/Ws/domainname.org/nginx;

        location / {
                location /static {
                }

                include    /etc/nginx/uwsgi_params;
                uwsgi_pass localhost:8000;
        }
}

Chris Seberino

unread,
Dec 11, 2017, 2:59:17 PM12/11/17
to Django users
I didn't have logging enabled in my settings.py.

Problem solved.
Reply all
Reply to author
Forward
0 new messages