views:

94

answers:

3

Readed all these topic http://stackoverflow.com/search?q=django.views.static.serve And it not helped :(

OS: Windows XP Python: 2.7 Django: 1.2.3

Media in
D:\bugtracker\static

With files:
docicons-note.gif
style.css

In settings.py i set:
MEDIA_ROOT = 'D:/bugtracker/static/'
MEDIA_URL = '/static/'

In urls.py i set:

urlpatterns = patterns('',
    (r'^media/(?P.*)$', 'django.views.static.serve',{'document_root':'settings.MEDIA_ROOT'}),
)

template: (read it without space in < tag>)
< !DOCTYPE html> < html lang='ru'>
< head>
< link rel="stylesheet" type="text/css" href="media/style.css" />
< /head>
< body>
< img src="{{MEDIA_URL}}/docicons-note.gif"/>
< /body>
< /html>

A: 

Static serving is only done via Django if the test server is running. If you're using a separate web server then you need to use that web server's facilities for serving static files, e.g. the Alias directive.

Ignacio Vazquez-Abrams
it's test server
aTei
+2  A: 

urls.py:

urlpatterns = patterns('',
    (r'^test_media/(?P<path>.*)$', 'django.views.static.serve',   
        'document_root':'settings.MEDIA_ROOT'}),
)

settings.py MEDIA_ROOT = 'path/to/media/folder/'

So if you have /test_media/photo.jpg will be used the value from MEDIA_ROOT: 'path/to/media/folder/photo.jpg'

template file:

< !DOCTYPE html> < html lang='ru'>
< head>
< link rel="stylesheet" type="text/css" href="/test_media/style.css" />
< /head>
< body>
< img src="/test_media/docicons-note.gif"/>
< /body>
< /html> 

This should be used only for development purposes. For production you should use a real web server.

Seitaridis
make as u say, but server say: "/test_media/style.css HTTP 1.1" 404 1744. Tryed: MEDIA_ROOT = 'D:/bugtracker/media_root/' and MEDIA_ROOT = 'D:\\bugtracker\\media_root\\'
aTei
Do you have the same 404 code for the photo(docicons-note.gif)? The css file is in the media_root folder or in media_root/css? You said the the media files are in D:\bugtracker\static. Then MEDIA_ROOT should be MEDIA_ROOT='D:/bugtracker/static'
Seitaridis
+1  A: 

Your settings.py has:

MEDIA_URL = '/static/'

But in urls.py your static serve app is pointing to "media". Change your static serve entry in urls.py to match the MEDIA_URL setting:

urlpatterns = patterns('',
    (r'^static/(?P.*)$', 'django.views.static.serve',{'document_root':'settings.MEDIA_ROOT'}),
)

Hopefully that works better for you.

Evan Porter