简体   繁体   English

Django静态文件

[英]Django staticfiles

I'm struggling getting staticfiles (CSS) to work on my Django site deployed to Openshift. 我正在努力让静态文件(CSS)在我的部署到Openshift的Django站点上工作。 I can workaround this by putting style info in the HTML templates, but the Django admin site stylesheets still will not load. 我可以通过在HTML模板中放置样式信息来解决这个问题,但Django管理站点样式表仍然无法加载。 Everything works locally, including with debug off. 一切都在本地工作,包括调试关闭。

Openshift stores staticfilesunder repo/ -> wsgi/ -> static/, where the main project directory is also under wsgi/. Openshift在repo / - > wsgi / - > static /下存储staticfiles,其中主项目目录也在wsgi /下。

Here are the relevant parts of settings.py: 以下是settings.py的相关部分:

ON_OPENSHIFT = True if 'OPENSHIFT_REPO_DIR' in os.environ else False
PROJECT_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), os.pardir)

if ON_OPENSHIFT:
    STATIC_ROOT = os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi', 'static')
else:
    STATIC_ROOT = ''

STATIC_URL = '/static/'

if ON_OPENSHIFT:
    STATICFILES_DIRS = (os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi', 'static'))
else:
    STATICFILES_DIRS = [os.path.join(PROJECT_DIR, 'static')]

I have a script that runs the following when deploying: 我有一个脚本在部署时运行以下命令:

cd $OPENSHIFT_REPO_DIR/wsgi/squadron
python manage.py collectstatic --noinput

I'm using Python 3.3 and Django 1.6, and referencing the following guides: 1 and 2 from the docs. 我正在使用Python 3.3和Django 1.6,并参考以下指南:文档中的12

What am I doing wrong? 我究竟做错了什么? I don't get an error message, just no stylesheets, either my own, or on Django admin. 我没有收到错误消息,没有样式表,无论是我自己的还是Django管理员。 When I use SCP, I can verify my stylesheet is in the correct Openshift directory. 当我使用SCP时,我可以验证我的样式表是否在正确的Openshift目录中。

This is the best source to read when you are trying to get OpenShift working with Django. 当您试图让OpenShift与Django一起工作时,这是阅读的最佳来源。

http://appsembler.com/blog/django-deployment-using-openshift/ http://appsembler.com/blog/django-deployment-using-openshift/

Some of this will be changing (for the better) with upcoming releases but this should help for now. 其中一些将随着即将发布的版本而变化(更好),但现在应该有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM