I am attempting to learn Django development with Bluemix Cloud Foundry and Python 3.5.3.
我正在尝试使用Bluemix Cloud Foundry和Python 3.5.3学习Django开发。
I have a hello world Website running at this time. But I cannot get static files like CSS to be served.
我这个时候有一个hello world网站。但我无法获得像CSS这样的静态文件。
I think my settings for finding static files are not correct.
我认为我找到静态文件的设置不正确。
My served page is meant to look like:
我的服务页面看起来像:
What I am getting is:
我得到的是:
I get the correct result locally with Debug = True
in settings.py, but not with Debug = False
. I cannot get the correct result when pushed to Bluemix, regardless of the Debug setting.
我在settings.py中使用Debug = True在本地获得正确的结果,但没有使用Debug = False。无论Debug设置如何,当推送到Bluemix时,我都无法获得正确的结果。
My project folders are set up like this:
我的项目文件夹设置如下:
the django staticfiles app is in my Installed_Apps variable.
django staticfiles应用程序位于我的Installed_Apps变量中。
In my settings.py file I have:
在我的settings.py文件中,我有:
...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
# STATICFILES_DIRS = [
# os.path.join(BASE_DIR, 'bluemixsite/static'),
# os.path.join(BASE_DIR, 'bluemixapp/static'),
# ]
STATICFILES_DIRS appeared to make no difference with finding static files.
STATICFILES_DIRS似乎与查找静态文件没有区别。
The template page (being loaded) includes the following:
模板页面(正在加载)包括以下内容:
...
{% load static %}
<link rel="stylesheet" type="text/css" href="/go.html?url={% static 'bluemixapp/stylesheet.css' %}" />
</head>
....
With Debug=False, when inspected in firefox, I can see this message under the style editor both locally and on bluemix:
使用Debug = False,在firefox中检查时,我可以在本地和bluemix上的样式编辑器下看到此消息:
The requested URL /static/bluemixapp/stylesheet.css was not found on this server.
So either I do not have the files in the correct location, or Django cannot resolve paths to the static files on the server.
所以要么我没有正确位置的文件,要么Django无法解析服务器上静态文件的路径。
I tried the collectstatic command which copied all static files into project_root/static/
folder but this made no difference.
我尝试了将所有静态文件复制到project_root / static /文件夹中的collectstatic命令,但这没有任何区别。
Apparently Bluemix refuses to run linux terminals (they freeze or crash when starting) so I can't do anything at the server end that way.
显然Bluemix拒绝运行linux终端(它们在启动时冻结或崩溃)所以我不能在服务器端做任何事情。
I cannot load the static files onto a separate server.
我无法将静态文件加载到单独的服务器上。
Any suggestions would be appreciated.
任何建议,将不胜感激。
1 个解决方案
#1
0
Try Loading static from static files instead:
尝试从静态文件加载静态:
{% load static from staticfiles %}
{%load static from staticfiles%}
As mentioned here.
如上所述。