Thanks for the great help. Daniel, good eye - I copied & pasted without looking too carefully, and was trying to access the folder one level up. Once I changed that, I can now access the file as David suggested, directly via the url: http://localhost:8000/site_media/autodiag_title.jpg
Brian, you understood me perfectly -- when I was asking about a tag, I was simply asking if django used a shortcut the way rails does, and {{MEDIA_URL}} is what I was looking for. Duh. :P However, {{MEDIA_URL}} currently returns nothing. I can't seem to access any of my settings.py vars from my views; I get no errors but no var either, it's just blank. I've tried both relative and absolute paths; my current code is this: settings.py MEDIA_ROOT = os.path.join(PROJECT_PATH, 'site_media') # which gives the right path in the interpreter MEDIA_URL = 'http://localhost:8000/site_media/' # which I verified as above urls.py if settings.DEBUG: urlpatterns += patterns('', (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': os.path.join(settings.PROJECT_PATH, 'site_media')}), ) My template has <img src="{{MEDIA_URL}}autodiag_title.jpg"/> but viewing source shows only <img src="autodiag_title.jpg"/> I've recopied the regex from the docs in case I made a typo, but I can't think of why I'm still getting no variable output. ? Thanks a bunch! On Jan 12, 4:58 pm, Daniel Roseman <roseman.dan...@googlemail.com> wrote: > On Jan 12, 8:59 pm, jazztpt <annacalla...@gmail.com> wrote: > > > > > Nope, that's not the problem. I had read that page, and another that > > suggested a slightly different syntax for the urlpatterns > > (fromhttp://rob.cogit8.org/blog). Sorry that I forgot to mention that I > > had already put Rob's version in my code -- I wasn't sure if it was > > necessary simply to show any images anywhere on your site (the example > > is of a set of images with a directory and links to each image). > > > This is what is currently in my urls.py file, after my other > > urlpatterns (and yes, DEBUG is set to True): > > if settings.DEBUG: > > urlpatterns += patterns('', > > (r'^media/(?P<path>.*)$', 'django.views.static.serve', > > {'document_root': os.path.join(settings.PROJECT_PATH, '..', > > 'media')}), > > ) > > > That page in the docs doesn't say anything about how to call this from > > the view. Are these files automatically accessed by an <img> tag? I > > didn't see any special image tag (like the image_tag in rails) in the > > template tags or in my search of the docs. > > Thanks > > OK, it sounds like you're getting a bit confused. > > Django doesn't do anything 'automatic' with images. As you've found > from those links, it is possible - under the development server only - > to get Django to serve up images in much the same way as Apache would > do so. In order to make that work, you've created a pattern in your > urls.py to serve the images from /media/. > > But there's still nothing automatic here. Django is simply serving > images on a url, and there's no such thing as a 'special image tag' to > make them appear. Your page is simply HTML, so you need to use a > normal HTML image tag - with the url you configured, ie /media/<path> > - to see the images. > > So, I would echo David Zhou's advice: what happens when you > enterhttp://127.0.0.1:8000/media/autodiag_title.jpg(presuming you're > running the dev server under the default address) directly into the > browser's URL box? Do you see the image, an error, or nothing at all? > > The second thing to check is whether your settings.py also has > ADMIN_MEDIA_PREFIX set to /media/, which it is by default. As > documented > here:http://docs.djangoproject.com/en/dev/ref/settings/#admin-media-prefix > this shouldn't be the same as the URL you use to serve images. If they > are the same, what's probably happening is that Django is setting / > media/ to serve the admin assets, rather than your project's ones. > This is why the documentation recommends using site_media as the URL > you serve your own images from. > > Thirdly, check the location of your images. The urlconf you posted has > the images being served from a 'media' directory one level *above* > your PROJECT_PATH setting (whatever that is - presumably your own > custom setting). Is this actually where the images live? > > Does any of this help? > -- > DR. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---