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 enter
http://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
-~----------~----~----~----~------~----~------~--~---

Reply via email to