Let me preface the following information by saying that I’m trying to
build this into the polls application that I built in the introductory
django tutorial. The document I’m looking at is here:

http://docs.djangoproject.com/en/1.2/howto/static-files/

And it says this:

How to do it¶

Here’s the formal definition of the serve() view:

def serve(request, path, document_root, show_indexes=False)

To use it, just put this in your URLconf:

(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': '/path/to/media'}),

...where site_media is the URL where your media will be rooted, and /
path/to/media is the filesystem root for your media. This will call
the serve() view, passing in the path from the URLconf and the
(required) document_root parameter.

Given the above URLconf:
•       The file /path/to/media/foo.jpg will be made available at the URL /
site_media/foo.jpg.
•       The file /path/to/media/css/mystyles.css will be made available at
the URL /site_media/css/mystyles.css.
•       The file /path/bar.jpg will not be accessible, because it doesn't
fall under the document root.

Of course, it's not compulsory to use a fixed string for the
'document_root' value. You might wish to make that an entry in your
settings file and use the setting value there. That will allow you and
other developers working on the code to easily change the value as
required. For example, if we have a line in settings.py that says:
STATIC_DOC_ROOT = '/path/to/media'
...we could write the above URLconf entry as:

from django.conf import settings
...
(r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': settings.STATIC_DOC_ROOT}),

...where site_media is the URL where your media will be rooted, and /
path/to/media is the filesystem root for your media. This will call
the serve() view, passing in the path from the URLconf and the
(required) document_root parameter.

Given the above URLconf:
•       The file /path/to/media/foo.jpg will be made available at the URL /
site_media/foo.jpg.
•       The file /path/to/media/css/mystyles.css will be made available at
the URL /site_media/css/mystyles.css.
•       The file /path/bar.jpg will not be accessible, because it doesn't
fall under the document root.

Of course, it's not compulsory to use a fixed string for the
'document_root' value. You might wish to make that an entry in your
settings file and use the setting value there. That will allow you and
other developers working on the code to easily change the value as
required. For example, if we have a line in settings.py that says:

STATIC_DOC_ROOT = '/path/to/media'

I’m trying to be able to have screen files be able to  reference
javascript and css code which is in external files.Based on what the
documentation above says I’ve coded my view code to look like this:

def serve(request, path, document_root, show_indexes=False)

I’ve also coded STATIC_DOC_ROOT like this:

STATIC_DOC_ROOT = '/polls/'

And I’ve coded the entry in my polls\urls.py like this:

    (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
{ 'document_root': settings.STATIC_DOC_ROOT }),

My folder where I have my javascript.js file is in this folder:

polls\site_media

where I  later hope to also add one or more other app-specific files/
folders for css as well. So any idea where I missing something to get
this to work properly? Currently I’m getting a TemplateSyntaxError.
Thanks for the help.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to