Answer the question
In order to leave comments, you need to log in
Django devserver - loading CSS, images, static files?
I ran into a problem - it does not load CSS and images. Googled a lot, tried examples - no effect. As a result, I got tired of hammering my project, I tried to implement the tutorial from here as the easiest one. And so I have:
settings.py
www.everfall.com/paste/id.php?mychvotp1za0
urls.py
www.everfall.com/paste/id.php?k4dap3jusrqu
views.py
www.everfall.com/paste/id. php?nl6o5szfs9ib
index.html
www.everfall.com/paste/id.php?595zhoraskg0
and style.css
www.everfall.com/paste/id.php?meo5xi4tyv47
The project lives in C:\Users\Soul Reaver\workspace\ girl\girl
There are .py files, and inside, respectively, there are folders media\Images\ and templates
In general, the result - nothing is loaded. The console on 404, as it usually happens, does not swear, it gives:
[27/Jan/2012 14:19:20] "GET / HTTP/1.1" 200 260 I
use Django 1.2.7.
I killed this evening, and I have no idea where to go. Put me on the right path please.
Answer the question
In order to leave comments, you need to log in
MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/media/admin/'
and everything will be fine.
we start the server - python manage.py runserver 8000 --nostatic everything
else seems to be ok for you, if you have any questions, knock on the door, there are contacts in the profile.
specify the full path in document_root, the last jang out of the box works with static files, you need to put them in the static dir
I usually use the following settings:
# settings.py
import os
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'media')
MEDIA_URL = '/media/'
# urls.py
from django.conf import settings
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
)
write the path in settings and don't forget
url(r'^static/(?P.*)$','django.views.static.serve',{'document_root':settings.STATIC_ROOT}),
url(r' ^media/(?P.*)$','django.views.static.serve',{'document_root':settings.MEDIA_ROOT}),
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question