在我的本地开发环境中
href={% static "datetimepicker-master/jquery.datetimepicker.css" %}/>
加载非常好。在heroku中,它表示CSRF错误,我认为是因为它试图从本地主机加载。
如何配置settings.py以正确加载静态文件?我的文件结构是:
/project
/app
/staticfiles
/mysite
答案 0 :(得分:1)
安装 dj-static (Django静态文件服务器)(Getting Started with Django on Heroku)
使用pip安装:
pip install dj-static
settings.py
# Static asset configuration
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
wsgi.py
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())