[Django]-Problems with SSL(django-sslserver) on Django project

4👍

Edited: My pull request has been merged. Static resources are served normally now.

The problem is that the runsslserver command is not implemented to serve static resources. A way to fix is to override get_handler in PATH_TO_PYTHON_SITE_PACKAGE/sslserver/management/commands/runsslserver.py like so:

# ...
from django.contrib.staticfiles.handlers import StaticFilesHandler
from django import get_version

# ...

class Command(runserver.Command):
    # ...

    help = "Run a Django development server over HTTPS"

    def get_handler(self, *args, **options):
        """
        Returns the static files serving handler wrapping the default handler,
        if static files should be served. Otherwise just returns the default
        handler.

        """
        handler = super(Command, self).get_handler(*args, **options)
        use_static_handler = options.get('use_static_handler', True)
        insecure_serving = options.get('insecure_serving', False)
        if use_static_handler:
            return StaticFilesHandler(handler)
        return handler

    # ...

You might want to get your site package path with

python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"

I’ve also submitted a pull request in case you want to branch, merge, and reinstall it as a package on your own.

Cheers

Leave a comment