首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提供本地静态文件的Whitenoise

提供本地静态文件的Whitenoise
EN

Stack Overflow用户
提问于 2018-04-10 06:53:56
回答 1查看 1.3K关注 0票数 3

正如它们的docs 这里中所描述的那样,我的应用程序配置为在本地提供静态文件。

我面临的唯一问题是,我无法确定是django还是whitenoise提供静态文件?

我遵循的步骤:

代码语言:javascript
复制
pip install whitenoise # install whitenoise
pip install brotlipy # install brotlipy for compression

INSTALLED_APPS = [

# default django apps
'django.contrib.messages',

# REMOVE IN PRODUCTION
# See: http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
'whitenoise.runserver_nostatic',

'django.contrib.staticfiles',
# other apps
]


# add white-noise middleware

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',

    # static files serving
    'whitenoise.middleware.WhiteNoiseMiddleware',


    'django.contrib.sessions.middleware.SessionMiddleware',
     # other middlewares
]


# add staticfiles 
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# run collecstatic
python manage.py collectstatic

# restart the server
python manage.py runserver

# This gives me following

[10/Apr/2018 12:12:40] "GET /static/debug_toolbar/css/print.css HTTP/1.1" 304 0
[10/Apr/2018 12:12:40] "GET /static/chartkick.js HTTP/1.1" 304 0
[10/Apr/2018 12:12:40] "GET /static/debug_toolbar/js/jquery_pre.js HTTP/1.1" 304 0

However, I expect something like this,

[10/Apr/2018 12:12:40] "GET /static/debug_toolbar/css/print.636363s6s.css HTTP/1.1" 304 0
[10/Apr/2018 12:12:40] "GET /static/chartkick.2623678s3cdce3.js HTTP/1.1" 304 0
[10/Apr/2018 12:12:40] "GET /static/debug_toolbar/js/jquery_pre.6276gdg3js8j.js HTTP/1.1" 304 0

如何检查whitenoise是否工作,以及它是否提供静态文件?

EN

回答 1

Stack Overflow用户

发布于 2019-12-05 18:01:06

自从你问这个问题已经有一段时间了,我想你已经找到答案了。但是,如果其他人无意中发现它,我发现如果您有DEBUG=False,Django将不会提供静态文件。因此,如果你有这样的设置,你仍然看到静态,这很可能是由怀特诺。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49747211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档