Hi there,
first, there's a difference between MEDIA files and STATIC files (since
1.3, I think). Media files are files uploaded by users, while static
files are usually persistent files on the server from the beginning,
eg. stylesheets, images, javascripts, robots.txt, etc.
It's good to keep these files separated, since static files are usualy
in VCS, while media files not.
As others said, it's convinient to use {{ MEDIA_URL }} and
{{ STATIC_URL }} variables in your templates. Just don't forget to use
RequestContext with proper context processor while rendering template:
https://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-static
Django should't server static/media files in production. They should be
served using your http server (nginx, apache, ...). In development,
however, you can add static files handler to your urls:
# your_project/urls.py
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
... # your url patterns
)
# Serve static and media files in development
from django.conf import settings
if settings.DEBUG:
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
media = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns = (media + staticfiles_urlpatterns() + urlpatterns)
Cheers,
Tom
Dne Mon, 15 Jul 2013 17:54:24 +0800
Phang Mulianto <
brav...@gmail.com> napsal(a):