本篇文章收集了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}),
]