[Django]-Django: 400 bad request syntax – what does this message mean?

107πŸ‘

βœ…

To address your actual question, this occurs if you’re trying to access the django server over https. Switch back to http and that error will disappear.

πŸ‘€David Horn

5πŸ‘

I get this kind of error when I run:

manage.py runserver ...

instead of:

manage.py runfcgi ...

because I’m behind Nginx.

When you use runserver, it is listening for standard http web requests. When you use runfcgi, it is listening for a different type of request, using fastcgi protocol instead of plain http.

πŸ‘€Mnebuerquo

3πŸ‘

You could refactor this maintenance middleware to achieve the result, because it checks the user status BEFORE processing content requests, which seems more djangonostic..

import settings
from django.http import HttpResponseRedirect


class MaintenanceModeMiddleware(object):
    """
    Maintenance mode for django

    If an anonymous user requests a page, he/she is redirected to the
    maintenance page.
    """
    def process_request(self, request):

        is_login = request.path in (
            settings.LOGIN_REDIRECT_URL,
            settings.LOGIN_URL,
            settings.LOGOUT_URL,
            settings.MAINTENANCE_PATH,
        )
        if (not is_login) and settings.MAINTENANCE and (not request.user.is_authenticated()):
            return HttpResponseRedirect(settings.MAINTENANCE_PATH)
        return None

Leave a comment