Maybe an example will clear it up. Its pretty much taken from the documentation. I leave the ADMIN_MEDIA_PREFIX as the default value.
# settings.py MEDIA_ROOT = '/home/django/django-projects/<project>/media/' MEDIA_URL = '/site_media/' # urls.py from django conf import settings if settings.DEBUG: urlpatterns += patterns('', (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), ) So, MEDIA_ROOT is the location on disk where my media files are. MEDIA_URL is the URL where they will be served from, for example http://mydomain.com/site_media/. In my example, you should notice the the MEDIA_URL is the URL that I use in the url pattern (minus the leading slash) That is my setup for development. When I move stuff to prod, I use apache/mod_python (on linux). So you no longer rely on Django so serve this static media. For me, I just set up soft links to the particular directories where the media files reside. For example (I refer to linux file paths, I've never used Django with Windows...): /var/www/media --> /home/django/django-trunk/django/contrib/admin/media /var/www/site_media --> /home/django/django-projects/<project>/media Did the example help? keith On Thu, Oct 9, 2008 at 6:04 PM, Robert <[EMAIL PROTECTED]>wrote: > > How is the MEDIA_URL reflected in my settings? If MEDIA_URL is '/ > site_media/', should my urls.py then be r'^site_media/$'? I fail to > understand the role it plays in all this. > > Thanks again for your replies. > > Kind regards, > Robert > > On Oct 9, 3:35 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote: > > Correct, they can't be the same. That's why I put /site_media/ to serve > > your projects media files in my reply. You can make them whatever you > want, > > but they have to be different. > > > > keith > > > > On Thu, Oct 9, 2008 at 4:36 PM, Robert > > <[EMAIL PROTECTED]>wrote: > > > > > > > > > Thanks for your reply, Keith. > > > > > I have made your suggested changes, but unfortunately I still cannot > > > display images. > > > > > On a whim, I put an image file in C:\Python25\Lib\site-packages\django/ > > > contrib/admin/media\img02.jpg and used the following code in my > > > template: > > > > > <img src="/media/img02.jpg" > > > > > The image now displays. It seems that it is not accessing my > > > designated media directory. > > > > > I read in the Django docs that MEDIA_URL and ADMIN_MEDIA_PREFIX cannot > > > both be the same URL (as in, they cannot both say '/media/'). Could > > > this be the problem? > > > > > All settings are currently exactly as you outlined above. > > > > > Kind regards, > > > Robert > > > > > On Oct 9, 1:45 pm, "Keith Eberle" <[EMAIL PROTECTED]> wrote: > > > > you need to change these: > > > > > > #from settings.py > > > > MEDIA_ROOT = 'D:/workspace/isiscore/media/' > > > > MEDIA_URL = '/site_media/' > > > > ADMIN_MEDIA_PREFIX = '/media/' > > > > > > #from urls.py > > > > from django.conf import settings > > > > (r'^media/(?P<path>.*)$', 'django.views.static.serve', > > > > { 'document_root': settings.MEDIA_URL, 'show_indexes': > > > > True, }), > > > > > > remember, MEDIA_URL, is a URL, not a filesystem path. > > > > > > keith > > > > > > On Thu, Oct 9, 2008 at 3:34 PM, Robert > > > > <[EMAIL PROTECTED]>wrote: > > > > > > > I'm hoping I've just missed a simple switch, but I'm trying to get > > > > > some simple CSS and images set up using the development server. > > > > > > > First, my setup: > > > > > > > from urls.py > > > > > (r'^media/(?P<path>.*)$', 'django.views.static.serve', > > > > > { 'document_root': 'D:/workspace/isiscore/media', 'show_indexes': > > > > > True, }), > > > > > > > from settings.py > > > > > > > MEDIA_ROOT = 'D:/workspace/isiscore/media/' > > > > > MEDIA_URL = 'D:/workspace/isiscore/media/' > > > > > ADMIN_MEDIA_PREFIX = '/media/' > > > > > > > I have tried putting an image into my template with: > src="css/images/ > > > > > img02.jpg" but nothing happens. The full path to the image file is > D: > > > > > \workspace\isiscore\media\css\images\img02.jpg. > > > > > > > The Problem: > > > > > > > When I try to load css (in my template as <link rel="stylesheet" > > > > > type="text/css" href="{{ MEDIA_URL }}css/default.css" />), nothing > > > > > happens. > > > > > > > When I set the browser tohttp:// > > > 127.0.0.1:8000/media/css/images/img02.jpg > > > > > , > > > > > I get a blank white page with the text "Page not found: > C:\Python25\Lib > > > > > \site-packages\django/contrib/admin/media\css/images/img02.jpg" at > the > > > > > top. It doesn't seem like the development server is even looking > in > > > > > the correct place. I'm also concerned by the seemingly random > > > > > assortment of backwards and forward slashes. > > > > > > > I'll mention this because it may be important, but I'm also getting > a > > > > > "TemplateSyntaxError: Caught an exception while rendering: nothing > to > > > > > repeat" whenever I save a file and then reload a page. Everything > > > > > works correctly, however, when I reload again. > > > > > > > Any and all help is kindly appreciated. > > > > > > > Kind regards, > > > > > Robert > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---