On Fri, Jul 11, 2008 at 4:37 AM, Eric Liu <[EMAIL PROTECTED]> wrote:
> When I create a app and try to show a image in the the html ,I ran
> into trouble that is the images can't be shown in the page.following
> is my page code:
>
> [...]
> <img src="/imgs/search.gif"></img>
> [...]

In HTML, the end tag of the img element must be omitted.  This isn't
related to your problem, but it might be nice to know.

> in urls.py:
>
> from django.conf.urls.defaults import *
> from mysite.view import current_time,ahead_hours
> from django.conf import settings
>
> urlpatterns = patterns('',
>  (r'^time/$', current_time),
>
> (r'^site_media/(?P<path>.*)$', 'django.views.static.serve',
> {'document_root': 'D:/test/mysite/mysite_media'}),
> )


This says that any URL path starting with /site_media/ will be handled
by django.views.static.serve and that the text following this prefix is
taken as the path to the file to be served relative to the directory
D:/test/mysite/mysite_media (the document_root).

This means that when a request arrives for a URL path like

  /site_media/PATH/TO/SOME/FILE.EXT

this view function will (try to) serve the file located on disk at

  D:/test/mysite/mysite_media/PATH/TO/SOME/FILE.EXT

So, going the other way, if you want the file

  D:/test/mysite/mysite_media/imgs/search.gif

the URL path to use is

  /site_media/imgs/search.gif

> and in settings.py:
> MEDIA_ROOT = "D:/test/mysite/mysite_media"
> MEDIA_URL = 'http://localhost:8080/mysite_media/'

This MEDIA_URL doesn't match what you've specified in your URLconf.
You'll want to pick one of the two.


Arien

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to