【Django】上线前调试须知

本篇文章收集了django部署前所遇到的BUG

django上线后media里面的uploads里面的上传的图片加载失败404解决

# setting.py
MEDIA_URL = "/media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")

# urls.py
from django.views.static import serve
from blog.settings import MEDIA_ROOT

urlpatterns = [
    # 处理 media 信息,用于图片获取
    url(r'^media/(?P<path>.*)', serve, {"document_root":MEDIA_ROOT}),
]

django上线后插件以及项目样式全无

# setting.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")

# 终端执行
python manage.py collectstatic

# urls.py
from django.conf.urls import url, re_path
from django.views.static import serve
from blog.settings import STATIC_ROOT

urlpatterns = [
     re_path(r'^static/(?P<path>.*)$', serve, {'document_root': STATIC_ROOT}),   
]

人已赞赏
其它

【npm】下包过程中报了while-parsing-near的错误

2020-10-26 17:50:38

其它

【Django】数据库的增删改查

2020-10-27 20:54:24

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索