On Mon, 2 Apr 2012 17:14:00 -0700 (PDT)
Homer <hi...@foxmail.com> wrote:

> I met "404" page not found when I try to enter 127.0.0.1:8000/cn/bedroom . 
> It says on the webpage that "C:/Django/final/media/bedroom" does not 
> exist". Why would this happen?

I am positive the problem is with your URL patterns:

> # urls.py
> urlpatterns = patterns('',
>     …
>     url(r'^cn/', include('final.photo.urls')),
>     url(r'^cn/(?P<path>.*)$', 'django.views.static.serve',
>         {'document_root': settings.MEDIA_ROOT}),
> )
> 
> # photo/urls.py
> urlpatterns = patterns('',
>     url(r'^$', List),
>     url(r'^/bedroom/', Detail),
> )

Trying to access 'cn/bedroom' _should_ redirect to view Detail, I guess.

But what happens is that 'cn/' gets stripped via the main level pattern,
including 'final.photo.urls'. There no match is found due to the leading
'/' in the second pattern: r'^/bedroom/'. Thus the search continues with
'cn/(?P<path>.*)$' in the top-level URL patterns which tries to access a
non-existing media file in settings.MEDIA_ROOT.

Therefore, to fix the issue, you should remove the leading forward slash
'/' in the second pattern in your photo/urls.py.

For reference, see the notes section in

  https://docs.djangoproject.com/en/1.4/topics/http/urls/#example
  – "There's no need to add a leading slash, because every URL has that.
  For example, it's ^articles, not ^/articles."

Best wishes,
Sebastian.

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