Turn off caching of static files in Django development server

后端 未结 9 2225
灰色年华
灰色年华 2020-11-30 04:52

Is there an easy way to turn off caching of static files in Django\'s development server?

I\'m starting the server with the standard command:

<
9条回答
  •  孤城傲影
    2020-11-30 05:29

    Use whitenoise. There's a lot of issues with the static file serving in runserver and they're all already fixed in whitenoise. It's also WAY faster.

    They've talked about just replacing the built-in static serving with it, but no one has gotten around to it yet.

    Steps to use it in development...

    Install with pip install whitenoise

    Add the following to the end of settings.py:

    if DEBUG:
        MIDDLEWARE = [
            'whitenoise.middleware.WhiteNoiseMiddleware',
        ] + MIDDLEWARE
        INSTALLED_APPS = [
            'whitenoise.runserver_nostatic',
        ] + INSTALLED_APPS
    

提交回复
热议问题