django cms doesn't see static folder

久未见 提交于 2019-12-24 00:57:24

问题


I'm very new to Django....and after hours of fighting I manage to install django cms in a virtual env. Creating some template and adding some page to my cms. Now I 'm trying to add some css....and I have create a static folder with inside css folder and my style.css. But it seems my cms doesnt see the static folder and I have a 404 error if I try to go :8000/static/css/style.css In my setting.py I have this

STATIC_ROOT = os.path.join(PROJECT_PATH, "static")
STATIC_URL = "/static/" 

not sure what s wrong pls help


回答1:


You should enable URL mapping for static resource by adding the following two lines into urls.py:

# redirects to static media files (css, javascript, images, etc.)
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': 'static/'}),

UPDATE 1: Check whether your project directory can be accessed by other user. chmod -R 755 might be helpful.


UPDATE 2: Make sure following lines are in settings.py

# List of finder classes that know how to find static files in various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

UPDATE 3: I checked the settings.py of my project, which is named webui:

STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    'webui/static',
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)



回答2:


I have been trying to integrate django-cms into an existing Digital Ocean Django install and I was encountering the same issues. While I was able to serve static files for everything else, for some reason my django-cms files kept returning a 404. I checked settings.py and permissions but I did not have much luck.

On Ubuntu 14.04 running Nginx and Gunicion

I edited

sudo nano /etc/nginx/sites-enabled/django

And I added the following code block

location /static/cms {
    alias /usr/local/lib/python2.7/dist-packages/cms/static/cms/;
}

Then I restarted Nginx and Gunicorn

sudo service nginx restart && sudo service gunicorn restart

and I was able to see all the missing static files




回答3:


I had the same problem. What helped me finally was to move the static files into a folder "static" of a custom app.



来源:https://stackoverflow.com/questions/16755465/django-cms-doesnt-see-static-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!