Django - 在Heroku中无法获取静态文件

时间:2016-08-24 14:22:13

标签: python django heroku

我使用Django创建了一个网页,并将其托管在Heroku Cloud中。这是我之前成功托管一个应用程序的第二个应用程序。但是对于这个应用程序,静态文件正在创建一些问题。它不在生产环境中获取静态文件。我尝试过几件事,但仍然无法正常工作。以下是我的settings.py

的几个代码
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ALLOWED_HOSTS = ['promagcareer.herokuapp.com']
TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [
      os.path.join(BASE_DIR, 'templates'),
      ],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
        ],
     },
  },
]

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

STATIC_ROOT = os.path.join(BASE_DIR, "static")

STATIC_URL = '/static/'

我在模板html中给出了{%load static%}。我尝试了很多东西,但仍然没有加载静态文件。可能是什么问题。

这是site的链接。 github project的链接。请帮助。提前谢谢。

以下是heroku日志--tail

2016-08-24T14:41:17.682678+00:00 app[web.1]: Not Found: /static/promag/js/jquery.magnific-popup.min.js
2016-08-24T14:41:18.169310+00:00 app[web.1]: Not Found: /static/promag/js/jquery.isotope.min.js
2016-08-24T14:41:18.207067+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.isotope.min.js" host=promagcareer.herokuapp.com request_id=295ee14c-abf9-4a0f-b7ba-38d9e118d3f3 fwd="150.107.23.147" dyno=web.1 connect=2ms service=7ms status=404 bytes=2338
2016-08-24T14:41:18.663379+00:00 heroku[router]: at=info method=GET path="/static/promag/js/swipe.js" host=promagcareer.herokuapp.com request_id=051ff48c-ea94-4375-b9d9-1c989449e1ec fwd="150.107.23.147" dyno=web.1 connect=4ms service=7ms status=404 bytes=2299
2016-08-24T14:41:18.657994+00:00 app[web.1]: Not Found: /static/promag/js/swipe.js
2016-08-24T14:41:18.882350+00:00 app[web.1]: Not Found: /static/promag/js/main.js
2016-08-24T14:41:18.888336+00:00 heroku[router]: at=info method=GET path="/static/promag/js/main.js" host=promagcareer.herokuapp.com request_id=aaf5dfac-4b8b-44fd-9e57-3ef5a5ff532e fwd="150.107.23.147" dyno=web.1 connect=0ms service=5ms status=404 bytes=2296
2016-08-24T14:41:19.102273+00:00 app[web.1]: Not Found: /static/promag/js/wow.min.js
2016-08-24T14:41:19.108087+00:00 heroku[router]: at=info method=GET path="/static/promag/js/wow.min.js" host=promagcareer.herokuapp.com request_id=352bf151-ca70-4a11-8ac0-b9582d3fdb9e fwd="150.107.23.147" dyno=web.1 connect=0ms service=5ms status=404 bytes=2305
2016-08-24T14:43:13.854149+00:00 heroku[api]: Starting process with command `python manage.py collectstatic` by jeril.work@gmail.com
2016-08-24T14:43:22.232867+00:00 heroku[run.3587]: Awaiting client
2016-08-24T14:43:22.225086+00:00 heroku[run.3587]: State changed from starting to up
2016-08-24T14:43:22.304420+00:00 heroku[run.3587]: Starting process with command `python manage.py collectstatic`
2016-08-24T14:43:31.942745+00:00 heroku[run.3587]: State changed from up to complete
2016-08-24T14:43:31.918016+00:00 heroku[run.3587]: Process exited with status 0
2016-08-24T14:43:40.118441+00:00 app[web.1]: Not Found: /static/promag/css/style.css
2016-08-24T14:43:40.074124+00:00 app[web.1]: Not Found: /static/promag/js/jquery-1.10.2.min.js
2016-08-24T14:43:40.127348+00:00 app[web.1]: Not Found: /static/promag/images/career.png
2016-08-24T14:43:40.118296+00:00 app[web.1]: Not Found: /static/promag/css/font-awesome.css
2016-08-24T14:43:40.122394+00:00 app[web.1]: Not Found: /static/promag/css/animate.css
2016-08-24T14:43:40.123029+00:00 app[web.1]: Not Found: /static/promag/css/bootstrap.min.css
2016-08-24T14:43:40.404323+00:00 app[web.1]: Not Found: /static/promag/js/jquery.easing.1.3.js
2016-08-24T14:43:40.346398+00:00 app[web.1]: Not Found: /static/promag/js/bootstrap.min.js
2016-08-24T14:43:40.557933+00:00 app[web.1]: Not Found: /static/promag/js/retina-1.1.0.min.js
2016-08-24T14:43:40.628917+00:00 app[web.1]: Not Found: /static/promag/js/jquery.smartmenus.bootstrap.min.js
2016-08-24T14:43:40.828045+00:00 app[web.1]: Not Found: /static/promag/js/jquery.isotope.min.js
2016-08-24T14:43:40.645692+00:00 app[web.1]: Not Found: /static/promag/js/jquery.magnific-popup.min.js
2016-08-24T14:43:40.614655+00:00 app[web.1]: Not Found: /static/promag/js/jquery.smartmenus.min.js
2016-08-24T14:43:40.886567+00:00 app[web.1]: Not Found: /static/promag/js/swipe.js
2016-08-24T14:43:41.046430+00:00 app[web.1]: Not Found: /static/promag/js/main.js
2016-08-24T14:43:41.099928+00:00 app[web.1]: Not Found: /static/promag/js/wow.min.js
2016-08-24T14:43:40.651092+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.smartmenus.bootstrap.min.js" host=promagcareer.herokuapp.com request_id=278e0a64-736c-47b9-bb33-9df30d382bca fwd="150.107.23.147" dyno=web.1 connect=1ms service=34ms status=404 bytes=2377
2016-08-24T14:43:40.574783+00:00 heroku[router]: at=info method=GET path="/static/promag/js/retina-1.1.0.min.js" host=promagcareer.herokuapp.com request_id=27700e8d-6a6a-40aa-a156-28f82e1c451c fwd="150.107.23.147" dyno=web.1 connect=1ms service=15ms status=404 bytes=2332
2016-08-24T14:43:39.852708+00:00 heroku[router]: at=info method=GET path="/career/" host=promagcareer.herokuapp.com request_id=6ee1b08d-8cbb-4c20-aa04-502b87c78b49 fwd="150.107.23.147" dyno=web.1 connect=1ms service=50ms status=200 bytes=5477
2016-08-24T14:43:40.658413+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.magnific-popup.min.js" host=promagcareer.herokuapp.com request_id=1903fe8c-8c3a-4af9-8b74-0bf8d38375e4 fwd="150.107.23.147" dyno=web.1 connect=1ms service=14ms status=404 bytes=2359
2016-08-24T14:43:40.895139+00:00 heroku[router]: at=info method=GET path="/static/promag/js/swipe.js" host=promagcareer.herokuapp.com request_id=75c61054-8ddf-46b5-8e1e-ab604f1a3cad fwd="150.107.23.147" dyno=web.1 connect=2ms service=6ms status=404 bytes=2299
2016-08-24T14:43:40.091524+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery-1.10.2.min.js" host=promagcareer.herokuapp.com request_id=6dbf19a0-6b3e-4392-9d74-5e340ae5c099 fwd="150.107.23.147" dyno=web.1 connect=1ms service=8ms status=404 bytes=2335
2016-08-24T14:43:41.095432+00:00 heroku[router]: at=info method=GET path="/static/promag/js/main.js" host=promagcareer.herokuapp.com request_id=cde55212-3393-4439-84fc-4a7a6a5ebb46 fwd="150.107.23.147" dyno=web.1 connect=1ms service=17ms status=404 bytes=2296
2016-08-24T14:43:40.125493+00:00 heroku[router]: at=info method=GET path="/static/promag/css/font-awesome.css" host=promagcareer.herokuapp.com request_id=34763ae8-4319-42b0-a358-cf0470825db8 fwd="150.107.23.147" dyno=web.1 connect=1ms service=6ms status=404 bytes=2326
2016-08-24T14:43:40.353330+00:00 heroku[router]: at=info method=GET path="/static/promag/js/bootstrap.min.js" host=promagcareer.herokuapp.com request_id=231dd103-1ee0-43b1-b413-846e01c734bc fwd="150.107.23.147" dyno=web.1 connect=1ms service=6ms status=404 bytes=2323
2016-08-24T14:43:40.625625+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.smartmenus.min.js" host=promagcareer.herokuapp.com request_id=069d6f11-16d8-46c9-a9a4-acb6b5c917f1 fwd="150.107.23.147" dyno=web.1 connect=1ms service=24ms status=404 bytes=2347
2016-08-24T14:43:40.151383+00:00 heroku[router]: at=info method=GET path="/static/promag/images/career.png" host=promagcareer.herokuapp.com request_id=55a6e9c6-5404-4cbb-a4b7-e69c3fa5fe30 fwd="150.107.23.147" dyno=web.1 connect=1ms service=13ms status=404 bytes=2317
2016-08-24T14:43:40.845095+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.isotope.min.js" host=promagcareer.herokuapp.com request_id=1d5878e5-13e5-413a-ae5c-770e3c0e83ca fwd="150.107.23.147" dyno=web.1 connect=1ms service=11ms status=404 bytes=2338
2016-08-24T14:43:40.132257+00:00 heroku[router]: at=info method=GET path="/static/promag/css/style.css" host=promagcareer.herokuapp.com request_id=9915ebd5-0c8b-4d6e-9d50-9376b1119317 fwd="150.107.23.147" dyno=web.1 connect=1ms service=6ms status=404 bytes=2305
2016-08-24T14:43:40.430185+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.easing.1.3.js" host=promagcareer.herokuapp.com request_id=f3a975c9-205a-4fae-98d2-9079752b9d83 fwd="150.107.23.147" dyno=web.1 connect=1ms service=8ms status=404 bytes=2335
2016-08-24T14:43:41.148636+00:00 heroku[router]: at=info method=GET path="/static/promag/js/wow.min.js" host=promagcareer.herokuapp.com request_id=6302a107-cb82-4ff1-ac43-6933a51aaddb fwd="150.107.23.147" dyno=web.1 connect=1ms service=12ms status=404 bytes=2305
2016-08-24T14:43:40.131264+00:00 heroku[router]: at=info method=GET path="/static/promag/css/bootstrap.min.css" host=promagcareer.herokuapp.com request_id=a1a00313-3192-45c2-ade0-d6e718f30e48 fwd="150.107.23.147" dyno=web.1 connect=1ms service=10ms status=404 bytes=2329
2016-08-24T14:43:40.131964+00:00 heroku[router]: at=info method=GET path="/static/promag/css/animate.css" host=promagcareer.herokuapp.com request_id=a89d285c-6a01-45bf-9818-3cb98d4867cd fwd="150.107.23.147" dyno=web.1 connect=1ms service=10ms status=404 bytes=2311
2016-08-24T14:46:47.652609+00:00 app[web.1]: Not Found: /static/promag/js/jquery-1.10.2.min.js
2016-08-24T14:46:47.719157+00:00 app[web.1]: Not Found: /static/promag/css/font-awesome.css
2016-08-24T14:46:47.744839+00:00 app[web.1]: Not Found: /static/promag/css/animate.css
2016-08-24T14:46:47.686882+00:00 app[web.1]: Not Found: /static/promag/css/style.css
2016-08-24T14:46:47.746422+00:00 app[web.1]: Not Found: /static/promag/js/bootstrap.min.js
2016-08-24T14:46:47.724693+00:00 app[web.1]: Not Found: /static/promag/images/career.png
2016-08-24T14:46:47.768166+00:00 app[web.1]: Not Found: /static/promag/js/jquery.easing.1.3.js
2016-08-24T14:46:47.791088+00:00 app[web.1]: Not Found: /static/promag/js/jquery.smartmenus.min.js
2016-08-24T14:46:47.813430+00:00 app[web.1]: Not Found: /static/promag/js/jquery.magnific-popup.min.js
2016-08-24T14:46:47.847221+00:00 app[web.1]: Not Found: /static/promag/js/jquery.isotope.min.js
2016-08-24T14:46:47.861463+00:00 app[web.1]: Not Found: /static/promag/js/swipe.js
2016-08-24T14:46:47.869106+00:00 app[web.1]: Not Found: /static/promag/js/main.js
2016-08-24T14:46:47.822603+00:00 app[web.1]: Not Found: /static/promag/js/bootstrap.min.js
2016-08-24T14:46:47.673050+00:00 app[web.1]: Not Found: /static/promag/css/bootstrap.min.css
2016-08-24T14:46:47.802422+00:00 app[web.1]: Not Found: /static/promag/js/jquery.smartmenus.bootstrap.min.js
2016-08-24T14:46:47.874797+00:00 app[web.1]: Not Found: /static/promag/js/wow.min.js
2016-08-24T14:46:47.772206+00:00 app[web.1]: Not Found: /static/promag/js/retina-1.1.0.min.js
2016-08-24T14:46:47.918516+00:00 app[web.1]: Not Found: /static/promag/js/jquery.easing.1.3.js
2016-08-24T14:46:47.995609+00:00 app[web.1]: Not Found: /static/promag/js/retina-1.1.0.min.js
2016-08-24T14:46:48.068254+00:00 app[web.1]: Not Found: /static/promag/js/jquery.smartmenus.min.js
2016-08-24T14:46:48.131985+00:00 app[web.1]: Not Found: /static/promag/js/jquery.smartmenus.bootstrap.min.js
2016-08-24T14:46:48.201657+00:00 app[web.1]: Not Found: /static/promag/js/jquery.magnific-popup.min.js
2016-08-24T14:46:48.291775+00:00 app[web.1]: Not Found: /static/promag/js/jquery.isotope.min.js
2016-08-24T14:46:48.366593+00:00 app[web.1]: Not Found: /static/promag/js/swipe.js
2016-08-24T14:46:48.436820+00:00 app[web.1]: Not Found: /static/promag/js/main.js
2016-08-24T14:46:48.532672+00:00 app[web.1]: Not Found: /static/promag/js/wow.min.js
2016-08-24T14:46:47.760216+00:00 heroku[router]: at=info method=GET path="/static/promag/css/animate.css" host=promagcareer.herokuapp.com request_id=15ad6cd4-8682-4617-891e-f83826bbfc1a fwd="50.130.91.84" dyno=web.1 connect=0ms service=96ms status=404 bytes=2311
2016-08-24T14:46:47.940990+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.easing.1.3.js" host=promagcareer.herokuapp.com request_id=4fea24c5-8311-4240-889b-a7b6a33f9156 fwd="50.130.91.84" dyno=web.1 connect=0ms service=32ms status=404 bytes=2335
2016-08-24T14:46:48.012855+00:00 heroku[router]: at=info method=GET path="/static/promag/js/retina-1.1.0.min.js" host=promagcareer.herokuapp.com request_id=42073752-6fe8-44b4-9cf9-22689f8d7d88 fwd="50.130.91.84" dyno=web.1 connect=0ms service=16ms status=404 bytes=2332
2016-08-24T14:46:47.852593+00:00 heroku[router]: at=info method=GET path="/static/promag/js/bootstrap.min.js" host=promagcareer.herokuapp.com request_id=9d9e4e74-b6e9-44da-b4fa-1f539a35bd9e fwd="50.130.91.84" dyno=web.1 connect=0ms service=33ms status=404 bytes=2323
2016-08-24T14:46:48.144956+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.smartmenus.bootstrap.min.js" host=promagcareer.herokuapp.com request_id=295ea2d0-46bf-40f4-a6be-3ae2ee942dcf fwd="50.130.91.84" dyno=web.1 connect=0ms service=12ms status=404 bytes=2377
2016-08-24T14:46:48.077690+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.smartmenus.min.js" host=promagcareer.herokuapp.com request_id=03e611d4-afd1-4c7c-b463-beec2c6c68ef fwd="50.130.91.84" dyno=web.1 connect=0ms service=8ms status=404 bytes=2347
2016-08-24T14:46:48.311315+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.isotope.min.js" host=promagcareer.herokuapp.com request_id=84df497c-50d7-4e4e-88d2-7f4e780a5c98 fwd="50.130.91.84" dyno=web.1 connect=0ms service=18ms status=404 bytes=2338
2016-08-24T14:46:48.237420+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.magnific-popup.min.js" host=promagcareer.herokuapp.com request_id=da71048f-556b-4513-8627-f134619f03b4 fwd="50.130.91.84" dyno=web.1 connect=0ms service=34ms status=404 bytes=2359
2016-08-24T14:46:47.458248+00:00 heroku[router]: at=info method=GET path="/career/" host=promagcareer.herokuapp.com request_id=f6f9a2a5-b530-4a6b-bd02-4417e8098847 fwd="50.130.91.84" dyno=web.1 connect=0ms service=45ms status=200 bytes=5477
2016-08-24T14:46:48.550355+00:00 heroku[router]: at=info method=GET path="/static/promag/js/wow.min.js" host=promagcareer.herokuapp.com request_id=a78c3578-3a51-4639-8dc6-f3d7325bd705 fwd="50.130.91.84" dyno=web.1 connect=0ms service=17ms status=404 bytes=2305
2016-08-24T14:46:48.475241+00:00 heroku[router]: at=info method=GET path="/static/promag/js/main.js" host=promagcareer.herokuapp.com request_id=82aa885d-2eea-4a38-9021-460063ede5f6 fwd="50.130.91.84" dyno=web.1 connect=0ms service=38ms status=404 bytes=2296
2016-08-24T14:46:48.380372+00:00 heroku[router]: at=info method=GET path="/static/promag/js/swipe.js" host=promagcareer.herokuapp.com request_id=91bc1737-dbfb-49b9-a9c3-3b13af80421e fwd="50.130.91.84" dyno=web.1 connect=0ms service=13ms status=404 bytes=2299
2016-08-24T14:46:47.754699+00:00 heroku[router]: at=info method=GET path="/static/promag/css/style.css" host=promagcareer.herokuapp.com request_id=867a41cd-89b4-493f-8d41-3e6fd1a9e154 fwd="50.130.91.84" dyno=web.1 connect=1ms service=58ms status=404 bytes=2305
2016-08-24T14:46:47.701725+00:00 heroku[router]: at=info method=GET path="/static/promag/css/bootstrap.min.css" host=promagcareer.herokuapp.com request_id=3bb9d7dc-4bbc-4a8e-a4bb-d39063b8a252 fwd="50.130.91.84" dyno=web.1 connect=0ms service=47ms status=404 bytes=2329
2016-08-24T14:46:47.825263+00:00 heroku[router]: at=info method=GET path="/static/promag/js/retina-1.1.0.min.js" host=promagcareer.herokuapp.com request_id=df0ad196-0589-400b-89a9-ceb5d4ce3481 fwd="50.130.91.84" dyno=web.1 connect=0ms service=15ms status=404 bytes=2332
2016-08-24T14:46:47.669707+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery-1.10.2.min.js" host=promagcareer.herokuapp.com request_id=9fbb183e-1e2b-4851-8175-361dd7393bb8 fwd="50.130.91.84" dyno=web.1 connect=0ms service=23ms status=404 bytes=2335
2016-08-24T14:46:47.781863+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.easing.1.3.js" host=promagcareer.herokuapp.com request_id=1ac22e72-7435-403c-9d24-fa378ff9aee8 fwd="50.130.91.84" dyno=web.1 connect=0ms service=18ms status=404 bytes=2335
2016-08-24T14:46:47.908853+00:00 heroku[router]: at=info method=GET path="/static/promag/js/swipe.js" host=promagcareer.herokuapp.com request_id=78fe5c0a-7704-4d26-9c31-b95468be1770 fwd="50.130.91.84" dyno=web.1 connect=0ms service=31ms status=404 bytes=2299
2016-08-24T14:46:47.760575+00:00 heroku[router]: at=info method=GET path="/static/promag/js/bootstrap.min.js" host=promagcareer.herokuapp.com request_id=ceda2868-3cf5-4632-a859-897056b3c96b fwd="50.130.91.84" dyno=web.1 connect=0ms service=35ms status=404 bytes=2323
2016-08-24T14:46:47.817604+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.smartmenus.bootstrap.min.js" host=promagcareer.herokuapp.com request_id=2e66aae5-4c54-49ee-a3ba-220a2d2f663a fwd="50.130.91.84" dyno=web.1 connect=0ms service=15ms status=404 bytes=2377
2016-08-24T14:46:47.885514+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.isotope.min.js" host=promagcareer.herokuapp.com request_id=a8823c7e-9150-4908-bab3-08e305ca531e fwd="50.130.91.84" dyno=web.1 connect=0ms service=53ms status=404 bytes=2338
2016-08-24T14:46:47.825012+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.magnific-popup.min.js" host=promagcareer.herokuapp.com request_id=ae98f655-9143-4200-b34e-ea470055a7ff fwd="50.130.91.84" dyno=web.1 connect=0ms service=10ms status=404 bytes=2359
2016-08-24T14:46:47.881764+00:00 heroku[router]: at=info method=GET path="/static/promag/js/wow.min.js" host=promagcareer.herokuapp.com request_id=7358f1d8-382d-41d8-a40a-0b72908d870c fwd="50.130.91.84" dyno=web.1 connect=0ms service=6ms status=404 bytes=2305
2016-08-24T14:46:47.743160+00:00 heroku[router]: at=info method=GET path="/static/promag/css/font-awesome.css" host=promagcareer.herokuapp.com request_id=5d42684e-86e2-4cbe-9aff-455d01980568 fwd="50.130.91.84" dyno=web.1 connect=0ms service=82ms status=404 bytes=2326
2016-08-24T14:46:47.733344+00:00 heroku[router]: at=info method=GET path="/static/promag/images/career.png" host=promagcareer.herokuapp.com request_id=58084327-9dd1-4a4c-9dbe-c9a8b448e8ca fwd="50.130.91.84" dyno=web.1 connect=0ms service=71ms status=404 bytes=2317
2016-08-24T14:46:47.876374+00:00 heroku[router]: at=info method=GET path="/static/promag/js/main.js" host=promagcareer.herokuapp.com request_id=4539f1c9-4e45-4d0c-8d6c-f9a266d65f56 fwd="50.130.91.84" dyno=web.1 connect=0ms service=20ms status=404 bytes=2296
2016-08-24T14:46:47.799763+00:00 heroku[router]: at=info method=GET path="/static/promag/js/jquery.smartmenus.min.js" host=promagcareer.herokuapp.com request_id=5e23c9b3-493f-4ccb-8af1-771989f3606e fwd="50.130.91.84" dyno=web.1 connect=0ms service=8ms status=404 bytes=2347

1 个答案:

答案 0 :(得分:1)

您应该将static/Promag文件夹重命名为static/promag,以匹配静态标记中的大小写,例如"{% static 'promag/css/font-awesome.css' %}

如果您的文件系统不区分大小写(例如Windows)或保留大小写(例如Mac),那么使用Progmag还是promag并不重要。但是,它确实对区分大小写的文件系统产生了影响。