静态文件Django在Heroku部署 [英] Statics Files Django on Heroku Deployment
问题描述
谢谢。
图片/样式正在试图引用。确保您的 STATIC_URL
是相对路径。还要确保您的 STATIC_ROOT
和 STATIC_URL
不一样。
例如:
settings / base.py
从unipath导入路径
#项目目录根假设:yourapp.settings.base
PROJECT_DIR =路径(__文件__)。祖先(3)
#静态文件
STATIC_ROOT = PROJECT_DIR.child(static)
#静态文件的URL前缀。
STATIC_URL ='/ static /'
此布局遵循类似于以下目录结构: / p>
project_name /
| - app 1
| - models.py
| - - views.py
...
| - project_name
| - 设置
| - base.py
| - 本地。 py
| - dev.py
...
另外默认当您上传项目时,Heroku应该收藏,如果您修改此设置确保调用:
python manage.py collectstatic
你可以检查静态文件是否存在于指定的文件夹中(在上面的例子中,它将在 / static /
I have my app runnning in Heroku, everything works really good with my models and forms, but there is a problem, I can't see any of my styles neither for my templates not for Django Grappelli, how can I solve this problem?
Thank you.
Check the path that your images/styles are trying to reference. Ensure that your STATIC_URL
is a relative path. Also ensure that your STATIC_ROOT
and STATIC_URL
are not the same.
Ex:
settings/base.py
from unipath import Path
# Project directory root assuming: yourapp.settings.base
PROJECT_DIR = Path(__file__).ancestor(3)
# Static files
STATIC_ROOT = PROJECT_DIR.child("static")
# URL prefix for static files.
STATIC_URL = '/static/'
This layout follows the directory structure similar to:
project_name/
|-- app 1
|-- models.py
|-- views.py
...
|-- project_name
|-- settings
|-- base.py
|-- local.py
|-- dev.py
...
Also by default Heroku should collectstatic when you upload your project however if you have modified this setting ensure to call:
python manage.py collectstatic
you can then check to see if static files are present in the specified folder (in the example above it would be in /static/
这篇关于静态文件Django在Heroku部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!