如何在Django中正确提供静态文件?在heroku上

时间:2019-02-03 08:28:41

标签: python django heroku

我的静态文件可以在DEBUG = True条件下工作,但是在DEBUG = False下则不能工作

我的settings.py

STATIC_URL = '/static/'


STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

urls.py

from django.conf.urls.static import static
from django.conf import settings

urlpatterns = [
#....
] + static(settings.MEDIA_URL , document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
我尝试的

命令      python manage.py collectstatic 它创建了一个文件夹,但无法呈现数据

home.html

<!DOCTYPE html>
{% load staticfiles %} # I try {% load static %} also
<html>
<head>
   <link rel="stylesheet" type="text/css" href="{% static 'app1css/home.css' %}">
      <title></title>
  </head>
  <body>
      <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do 
     .</p>
     </body>
   </html>

这是我的项目结构

C:.
├───app1
│   ├───migrations
│       │   └───__pycache__
│           └───__pycache__
├───mysite
│   ├───static
│   │   └───app1css
│   └───__pycache__
├───static
│   ├───admin
│   │   ├───css
│   │   │   └───vendor
│   │   │       └───select2
│   │   ├───fonts
│   │   ├───img
│   │   │   └───gis
│   │   └───js
│   │       ├───admin
│   │       └───vendor
│   │           ├───jquery
│   │           ├───select2
│   │           │   └───i18n
│   │           └───xregexp
│   └───app1css
└───templates
    └───app

我已经阅读了许多与此相关的问题,但无法解决我的问题。我已使用此设置(静态文件)将博客上传到heroku,但它给了我SERVERERROR 500(debug = False)。我尝试将{%load static%}更改为{%load staticfiles%},但仍然

Django版本2.1.5 服务器apache python版本3.6.7

0 个答案:

没有答案
相关问题