OpenShift Django上的静态文件 [英] Static files on OpenShift Django

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

问题描述

我在安装静态文件时遇到问题,即从我的html页面所需的样式表和图像。我似乎不知道为什么没有找到这些静态图像。这是我在 settings.py

I'm having issues serving up static files - i.e. style sheets and images required from my html pages. I cannot seem to fathom why these static images are not being found. Here is what I have in my settings.py

    STATIC_URL = PROJECT_PATH + '/static/'

# Additional locations of static files
STATICFILES_DIRS = (PROJECT_PATH + "/static/",)

STATIC_ROOT = "/static/"


# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

我收到404错误,当我尾巴进入日志。但是我无法弄清楚OpenShift正在寻找这些图像的位置或调试方式。我试过使用 STATIC_URL ='/ static /',但这不起作用。

I'm getting a 404 error, when I tail into the log. But I cannot figure out where or debug or figure out where OpenShift is looking for these images. I've tried using STATIC_URL = '/static/' but that doesn't work either.

推荐答案

1)您已经混合了STATIC_URL和STATIC_ROOT变量。

1) You've mixed up STATIC_URL and STATIC_ROOT variables.

STATIC_ROOT:需要指向目录您希望收集静态文件。在这种情况下,它似乎是PROJECT_PATH +'/ static /'。 确保此目录是正确的。

STATIC_ROOT: Needs to point to the directory where you want your static files to be collected. In this case, it seems it is PROJECT_PATH + '/static/'. Make sure this directory is correct.

STATIC_URL:您的静态文件被访问的url。 / static /是正确的。

STATIC_URL: The url your static files are accessed. /static/ is correct.

删除STATICFILES_DIRS变量。它不能与STATIC_ROOT相同,因为首先告诉Django在哪里查找静态文件,其次告诉Django收集静态文件时,STORE静态文件。

Remove the STATICFILES_DIRS variable. It can't be the same as STATIC_ROOT because first tells Django where to FIND static files and second tells Django where to STORE static files when they are collected.

2)如果您正在使用Openshift,正如@ timo.rieber指出的那样,您将需要一个action_hook来部署来告诉它收集静态文件。

2) If you are working with Openshift, as @timo.rieber points out, you will need an action_hook for deploy to tell it to collect your static files.

3)您的static_root文件夹不能在您的项目的任何地方,因为Openshift网络服务器将找不到它。它应该在你的项目/ wsgi / static< ---(因此,这将是STATIC_ROOT变量值)。

3) Your static_root folder can't be anywhere in your project because Openshift webserver won't find it. It should be under yourproject/wsgi/static <--- (Thus, this will be the STATIC_ROOT variable value).

正如我已经在另一个问题中回答了你,开始一个新的项目从头开始Openshift是痛苦的。我写了一篇关于创建一个新项目以使其与Openshift 合作的帖子,以及您还可以访问在那里引用的提交,将重定向到一个基本的Openshift项目,该工程。您还可以从 Openshift repo 下载基本项目,但它遵循一个旧的(但仍然工作)的项目结构。您现在可以使用更简单的python应用程序的项目结构

As I already answered you in another question, starting a new project from scratch for Openshift is painful. I've wrote a post about creating a new project to make it work with Openshift and you can also visit the commit referenced there which will redirect you to a basic Openshift project which works. You can also download basic project from Openshift repo but it follows an old (but still working) project structure. You can now use a simpler project structure for python apps

这篇关于OpenShift Django上的静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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