Django: how to add static files

I read all these topics https://stackoverflow.com/search?q=django.views.static.serve And this did not help :(

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 install:

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

template: (read it without a 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>

+1
source share
3 answers

urls.py:

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

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

, /test _media/photo.jpg MEDIA_ROOT: '//media/folder/photo.jpg'

:

< !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> 

. -.

+5

settings.py :

MEDIA_URL = '/static/'

urls.py "media". urls.py, MEDIA_URL:

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

, .

+2

Django, . -, - , . Alias.

0

Source: https://habr.com/ru/post/1771144/


All Articles