Django 在 Debug=True 时, 不需要配置. Django会在App中需找STATIC路径. 因为服务器一直用Nginx配置STATIC路径, 所以一直没有配置开发环境的STATIC路径, 但需要测试生产环境还是不方便, 所以设置一下Django中的STATIC路由.
配置
project/urls.py
from django.views.static import serve
urlpatterns = [
url(r'^static/(?P<path>.*)$', serve, {'document_root': settings.STATIC_ROOT}, name='static'),
...
]
project/settings.py
INSTALLED_APPS = [
'django.contrib.staticfiles',
......
]
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'apps/appname/static/'),
)
路径
STATIC
APP_STATIC
部署时使用需收集App下的STATIC文件到project/static/, 命令
python manage.py collectstatic
End
AD
https://dxx.fun/c/Python.html https://zfdev.com
|