From dfc358ada84272d584d48757561ed58e342c35a8 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Tue, 12 Jun 2007 01:12:26 +0000 Subject: [PATCH] WINDOWS USERS: (This applies to UNIX/Linux as well, but is probably more interesting to Windows users). You may now open up your settings.py file and add SERVE_MEDIA=True to serve media directly from Django. This is useful when you're running Django's built-in development server and want to be able to get to your CSS/Images, or if you have an apache server and don't want to configure a media location. Note that this is NOT something you want in a production environment, as it's slow, and may pose security risks. However, this will get you up and running very quickly for web work. The new setting, SERVE_MEDIA, is defaulted to False and is in the latest settings.py.dist file. --- settings.py.dist | 7 +++++++ urls.py | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/settings.py.dist b/settings.py.dist index beea8a394b..1a97997052 100755 --- a/settings.py.dist +++ b/settings.py.dist @@ -45,6 +45,13 @@ SITE_ID = 1 # to load the internationalization machinery. USE_I18N = False +# If you'd like to serve media files via Django (strongly not recommended!), +# set SERVE_MEDIA to True. This is appropriate on a developing site, or if +# you're running Django's built-in test server. Normally you want a webserver +# that is optimized for serving static content to handle media files (apache, +# lighttpd). +SERVE_MEDIA = False + # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" MEDIA_ROOT = '%s/media' % (BASE_PATH) diff --git a/urls.py b/urls.py index 56e7b798cd..9ccea53526 100755 --- a/urls.py +++ b/urls.py @@ -7,11 +7,22 @@ # from django.conf.urls.defaults import * +import settings urlpatterns = patterns('', - # Admin interface - (r'^admin/', include('django.contrib.admin.urls')), + # Admin interface + (r'^admin/', include('django.contrib.admin.urls')), - # Front page - (r'^', include('apps.website.urls')), + # Front page + (r'^', include('apps.website.urls')), ) + +# If you'd like to serve media files via Django (strongly not recommended!), +# open up your settings.py file and set SERVE_MEDIA to True. This is +# appropriate on a developing site, or if you're running Django's built-in +# test server. Normally you want a webserver that is optimized for serving +# static content to handle media files (apache, lighttpd). +if settings.SERVE_MEDIA: + urlpatterns += patterns('', + (r'^media/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), + ) \ No newline at end of file