Static files on OpenShift Django

前端 未结 5 1682
悲&欢浪女
悲&欢浪女 2020-12-16 06:59

I\'m having issues serving up static files - i.e. style sheets and images required from my html pages. I cannot seem to fathom why these static images are not being found. H

5条回答
  •  轮回少年
    2020-12-16 07:29

    1) You've mixed up STATIC_URL and STATIC_ROOT variables.

    STATIC_ROOT: Needs to point to the directory where you want your static files to be collected. In this case, it seems it is PROJECT_PATH + '/static/'. Make sure this directory is correct.

    STATIC_URL: The url your static files are accessed. /static/ is correct.

    Remove the STATICFILES_DIRS variable. It can't be the same as STATIC_ROOT because first tells Django where to FIND static files and second tells Django where to STORE static files when they are collected.

    2) If you are working with Openshift, as @timo.rieber points out, you will need an action_hook for deploy to tell it to collect your static files.

    3) Your static_root folder can't be anywhere in your project because Openshift webserver won't find it. It should be under yourproject/wsgi/static <--- (Thus, this will be the STATIC_ROOT variable value).

    As I already answered you in another question, starting a new project from scratch for Openshift is painful. I've wrote a post about creating a new project to make it work with Openshift and you can also visit the commit referenced there which will redirect you to a basic Openshift project which works. You can also download basic project from Openshift repo but it follows an old (but still working) project structure. You can now use a simpler project structure for python apps

提交回复
热议问题