Django – 在本地和Heroku上都找不到静态文件

我在使用Django和Heroku上的Docker的静态文件时遇到问题。 当我打开应用程序,我在Heroku上得到这样的错误:

2017-07-13T13:37:43.271635+00:00 heroku[router]: at=info method=GET path="/static/rest_framework/js/default.js" host=myapp.herokuapp.com request_id=3bfd8d31-193e-48e8-bb6e-aee9f353ffee fwd="109.173.154.199" dyno=web.1 connect=1ms service=15ms status=404 bytes=291 protocol=https 

在本地就像这样:

 django_1 | [13/Jul/2017 13:35:01] "GET /static/rest_framework/js/default.js HTTP/1.1" 404 109 

我试图做很多答案的基础上,例如这个主题 ,不幸的是没有任何工作。 有什么build议么?

基于Heroku文档的我的settings.py

 PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(PROJECT_ROOT, 'static'), ) STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' 

我添加了whitenoiserequirements.txt

wsgi.py:

 import os from django.core.wsgi import get_wsgi_application from whitenoise.django import DjangoWhiteNoise os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") application = get_wsgi_application() application = DjangoWhiteNoise(application) 

解决scheme我无法运行python3 manage.py collectstatic因为No such file or directory static in my project treeNo such file or directory static in my project tree 。 然后python3 manage.py collectstatic解决了我的问题。