Django MEDIA_URL and MEDIA_ROOT issue with CSS -
i'm having similar problem this question unfortunately none of solutions seem working me.
essentially have following, simple directory:
ulogin - models.py - tests.py - views.py - media - screen.css - templates - utemplate - index.html
in settings.py
have following defined:
media_root = '../compwebsite/ucode/ulogin/media' media_url = '/media/'
and in index.html
have following trying reference screen.css
<html> <head> <title> yay title </title> <link rel="stylesheet" href="{{ media_url }}screen.css"> <!--and more...-->
my urls.py
have following:
from django.conf.urls import patterns, include, url django.conf import settings django.conf.urls.static import static if settings.debug: # static files (images, css, javascript, etc.) urlpatterns += patterns('', (r'^media/(?p<path>.*)$', 'django.views.static.serve', { 'document_root': settings.media_root}))
no matter do, can't reference screen.css
work. i'm uncertain of how fix based on other questions here on site. thank , let me know if need more info!
static files should placed in 'static' directory; django look. 'media' directory meant hold user-uploaded files, copied on static directory when django server runs.
change media_url
references static_url
you shoudn't have use urlconf manage static files @ all.
as django settings, it's not idea hard code absolute paths in case changed (i.e. when pushed deployment server).
a better idea this:
from os import path project_root = path.abspath(path.dirname(path.dirname(__file__))) media_root = path.join(project_root, 'media/') media_url = '' static_root = '' static_url = '/static/' staticfiles_dirs = ( path.join(project_root, 'static/'), )
this ensure django using correct absolute path regardless of project on system.
you can enable defaultstorefinder in staticfiles_finders
although shouldn't necessary.
Comments
Post a Comment