Skip to main content
 首页 » 编程设计

python之Django 支持生产静态文件

2025年04月02日35telwanggs

<分区>

在我的 settings.py 中,

STATIC_ROOT = '/home/khantthulinn/webapps/static_media/' 
STATIC_URL = '/home/khantthulinn/webapps/static_media/' 

在我的 urls.py 中,

urlpatterns = patterns('', 
 
    url(r'^admin/', admin.site.urls), 
 
    #Media 
    (r'^media/(?P<path>.*)$', 'django.views.static.serve', { 
        'document_root': settings.MEDIA_ROOT}), 
 
)+ static(settings.STATIC_ROOT, document_root=settings.STATIC_ROOT) 

之后,在我的网络服务器中,我复制了静态文件。

python manage.py collectstatic 

一切都很好,我看得很正确。

当我更改 DEBUG = False 时,问题就来了。

我已经读过了,但我不明白。

https://docs.djangoproject.com/en/1.10/howto/static-files/deployment/

我也从这里阅读了解决方案。

Why does DEBUG=False setting make my django Static Files Access fail?

With debug turned off Django won't handle static files for you any more - your production web server (Apache or something) should take care of that.

我想试试。我该怎么办?

我不想运行它,因为它不安全。

manage.py runserver --insecure