久久久久久AV无码免费看大片,亚洲一区精品人人爽人人躁,国产成人片无码免费爱线观看,亚洲AV成人无码精品网站,为什么晚上搞的时候要盖被子

django生產(chǎn)環(huán)境配置static,DEBUG=False

時(shí)間:2022-01-20 22:03:44 類型:python
字號(hào):    

  1.首先setttings.py里面設(shè)置

STATIC_ROOT = os.path.join(BASE_DIR , "mystatic/static") ## 新增行
DEBUG = False
ALLOWED_HOSTS = ['127.0.0.1', 'localhost']

  2.執(zhí)行python manage.py collectstatic收集靜態(tài)文件, 把各個(gè)模塊下的static下的文件拷貝到STATIC_ROOT指定的目錄下

  3.在urls.py里面添加路由映射

from django.urls import path,include,re_path
from home import index
from django.conf import settings
import os



urlpatterns = [
    #path('admin/', admin.site.urls),
    path("",index.index),
    path('test/', include("test.urls")),
    path('yt/', include('zz.urls')),
    path('ueditor/',include('DjangoUeditor.urls'))
]

if not settings.DEBUG:
    from django.views import static
    urlpatterns += [re_path(r'^static/(?P<path>.*)$', static.serve,
      {'document_root': settings.STATIC_ROOT}, name='static')]
    urlpatterns += [re_path(r'^media/(?P<path>.*)$', static.serve,
                            {'document_root': settings.MEDIA_ROOT}, name='media')]

if settings.DEBUG:
    from django.conf.urls.static import static
    media_root = os.path.join(settings.BASE_DIR,settings.MEDIA_ROOT)
    urlpatterns += static(settings.MEDIA_URL, document_root = media_root)
    #映射 /media   到statics/media目錄


<