美文网首页
项目中静态文件路由配置

项目中静态文件路由配置

作者: ___大鱼___ | 来源:发表于2018-11-01 15:05 被阅读5次

    urls.py

    
    from django.conf.urls import url, include
    from django.contrib import admin
    from django.views.static import serve
    from django.conf.urls.static import static
    from django.conf import settings
    
    from . import views
    
    
    urlpatterns = [
    
        ...
        url(r'^static/(?P<path>.*)$', serve, {'document_root': settings.STATIC_ROOT}),
    ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    
    handler404 = 'TY_RMS_Multiple_Manage.views.page_not_found'
    
    

    settings.py

    STATIC_URL = '/static/'
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'static')
    ]
    # 部署路径
    if not DEBUG:
        STATIC_ROOT = '/home/blog/static_file'
    

    相关文章

      网友评论

          本文标题:项目中静态文件路由配置

          本文链接:https://www.haomeiwen.com/subject/zqdxxqtx.html