静态文件Django在Heroku部署 [英] Statics Files Django on Heroku Deployment

查看:150
本文介绍了静态文件Django在Heroku部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的应用程序在Heroku奔跑,一切都与我的模型和表单非常好,但有一个问题,我看不到任何我的样式,不是我的模板不是Django Grappelli,我如何解决这个问题?



谢谢。

解决方案

图片/样式正在试图引用。确保您的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆