S
S
S0ulReaver2012-01-27 11:39:12
Django
S0ulReaver, 2012-01-27 11:39:12

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

5 answer(s)
P
Pavel Zagrebelin, 2012-01-27
@S0ulReaver

MEDIA_URL = '/media/'
ADMIN_MEDIA_PREFIX = '/media/admin/'
and everything will be fine.

I
igorakintev, 2012-01-27
@igorakintev

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.

G
Gasoid, 2012-01-27
@Gasoid

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

D
Damir Abdullin, 2012-01-27
@damirazo

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}),
    )

I put all media resources in the media folder of the project.
In django 1.3.1, this is enough for me for a dev server. And if you want to use the media resources of some third-party application (for example, django-admin-tools), then I add the path to them in the STATICFILES_DIRS list of the settings.py file

I
igorakintev, 2012-01-27
@igorakintev

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 question

Ask a Question

731 491 924 answers to any question