LINE Chatbot 建立遊戲化體驗APP|Day5.5 CSS加載沒有成功怎麼辦?

You most likely have solved the problem, however this is for anyone else who has the problem in the future.

Most sites and people say that you need to update the ALLOWED_HOSTS in settings.py like so: ['www.beta800.net', '127.0.0.1'] (or ['*'] for a quick test, NOT for production).

For me, this didn’t solve the problem, though it is important to update ALLOWED_HOSTS either way. My problem was that my app was missing the static files folders. If the logging shows you an error similar to this: UserWarning: No directory at:/app/static/ warnings.warn(u'No directory at: {}'.format(root)) this is the problem in your app as well. If that is the case, follow these steps:

  1. Locally, change the DEBUG property in settings.py to True.
  2. Make sure you have the following properties set in settings.py:
# The URL to use when referring to static files (where they will be served from)
STATIC_URL = '/static/'

# The absolute path to the directory where collectstatic will collect static files for deployment.
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

# Simplified static file serving.
# https://warehouse.python.org/project/whitenoise/
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
  1. Locally, add a folder named static to the root folder.
  2. Locally, run python manage.py collectstatic. This should create another folder in your app’s root folder called staticfiles.
  3. Now you can set the DEBUG property in settings.py to False and deploy your app.

參考資料:https://stackoverflow.com/questions/53694341/heroku-django-deploy-why-am-i-getting-an-error-500-with-successful-deploy-and-s

Leave a Comment

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

回到頂端