在Django应用程序中加载静态文件

时间:2019-11-18 14:47:49

标签: django gunicorn cloudfoundry

我有一个django应用程序,试图从django项目中加载前端。 我的index.html是:

<link rel="icon" type="image/x-icon" href="favicon.ico">
  {% load static %}
<link rel="stylesheet" href="{% static "styles.38614f36c93ac671679e.css" %}"></head>
<body>
<app-root></app-root>
{% load static %}
<script type="text/javascript" src="{% static "runtime.a66f828dca56eeb90e02.js" %}"></script><script type="text/javascript" src="{% static "polyfills.f3fc5ca24d1323624670.js" %}"></script><script type="text/javascript" src="{% static "scripts.5bde77e84291ce59c080.js" %}"></script><script type="text/javascript" src="{% static "main.e7b9143f2f482d6d3cc7.js" %}"></script></body>
</html>

并且在项目文件的settings.py中,我添加了静态文件设置:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

我的项目结构是:

apt.yml     DCMS_API/  infra/  manage.py*    odbc-cfg/  requirements.txt  static/       templates/
Authorize/  facility/  manifest.yml  Procfile   runtime.txt

当我将代码上传到Cloud Foundry并尝试运行其显示的应用程序时

ERR Not Found: /static/runtime.a66f828dca56eeb90e02.js
ERR Not Found: /static/styles.38614f36c93ac671679e.css
ERR Not Found: /static/polyfills.f3fc5ca24d1323624670.js
ERR Not Found: /static/scripts.5bde77e84291ce59c080.js
ERR Not Found: /static/main.e7b9143f2f482d6d3cc7.js

我想念什么?

1 个答案:

答案 0 :(得分:0)

您是否运行python manage.py collectstatic吗?