简体   繁体   English

使用Django的Openshift上的静态文件

[英]Static files on Openshift with Django

I can't found my static files like css, js and picture. 我找不到像css,js和picture这样的静态文件。 I get 404 error page. 我得到404错误页面。

In my settings django I have 在我的设置django我有

STATIC_ROOT = '/var/lib/openshift/*id*/app-root/repo/*project*/*app*' 
STATIC_URL = '/static/'

and my filesystem are 我的文件系统是

 - project
   - app
     - wsgi.py
     - static # I also tried to move this folder in wsgi folder
       - css
         - base.css
     - ... 

I tried to move the static folder in wsgi folder created before . 我试图在之前创建的wsgi文件 中移动静态文件 I also tried to move my static folder or wsgi folder in data folder of openshift without success. 我还试图 openshift的数据文件夹中移动我的静态文件夹或wsgi文件夹,但没有成功。

I follow few help posts from Stackoverflow without found my answer 我在Stackoverflow上发布了一些帮助帖子而没有找到我的答案

Can you help me to configure my static folder ? 你能帮我配置我的静态文件夹吗?

Thanks 谢谢

in your settings.py make sure you have: 在您的settings.py中确保您拥有:

import os
import sys

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static_files'),
                   )  # create static_files dir and place there your static  
                      # files to be collected, as static is the destination
                      # directory of your local and other Django 
                      # modules static files 

STATIC_ROOT = os.path.join(BASE_DIR, 'static', )
STATIC_URL = 'http://yourdomain.com/static/'

once done run 一旦完成运行

 ./manage.py collectstatic 

make sure you have tree like 确保你有树

 yourproject+
            |
            +-yourproject
            |           | 
            |           +urls.py  
            |           |
            |           +settings.py
            |           |
            |           +wsgi.py
            |
            +manage.py
            |
            +static_files
            |
            +static

You also need to make sure your manage.py is modified to be: 您还需要确保将manage.py修改为:

import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")

    from django.core.management import execute_from_command_line  

    execute_from_command_line(sys.argv)

and wsgi.py to be 和wsgi.py是

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")

application = get_wsgi_application()

wsgi.py中我必须有sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'])) os.environ['DJANGO_SETTINGS_MODULE' ] = 'project.settings.app'和我的settings.py STATIC_ROOT = os.path.join(os.getenv('OPENSHIFT_REPO_DIR'), 'wsgi/static', ) STATIC_URL = '/static/'我的网站repo project ... wsgi static wsgi.py的文件系统repo project ... wsgi static wsgi.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM