By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,737 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,737 IT Pros & Developers. It's quick & easy.

Django: 404 page not found

P: 11
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?

urls.py:
Expand|Select|Wrap|Line Numbers
  1. from django.conf.urls.defaults import *
  2. from final import settings
  3.  
  4. from django.contrib import admin
  5.  
  6. admin.autodiscover()
  7.  
  8. urlpatterns = patterns('',
  9.  
  10.     url(r'^admin/', include(admin.site.urls)),
  11.  
  12.     url(r'^cn/', include('final.photo.urls')),
  13.  
  14.     url(r'^cn/(?P<path>.*)$', 'django.views.static.serve',
  15.  
  16.         {'document_root': settings.MEDIA_ROOT}),
  17.  
  18. )
photo/urls.py:
Expand|Select|Wrap|Line Numbers
  1. from django.conf.urls.defaults import *
  2.  
  3. from final.photo.views import List, Detail
  4.  
  5. urlpatterns = patterns('',
  6.  
  7.     url(r'^$', List),
  8.     url(r'^/bedroom/', Detail),
  9.  
  10. )
  11.  
photo/views.py:
Expand|Select|Wrap|Line Numbers
  1. # Create your views here.
  2.  
  3. from django.template import loader, Context, RequestContext
  4.  
  5. from django.http import HttpResponse
  6.  
  7. from final.photo.models import Image, Audio, Pinyin, SImage
  8.  
  9. from django.shortcuts import render_to_response
  10.  
  11. def List(request):
  12.  
  13.     ShowSImage = SImage.objects.all()
  14.     ShowLink = Image.objects.all()
  15.  
  16.     context = RequestContext(request, {
  17.  
  18.          'ShowSImage': ShowSImage, 'ShowLink': ShowLink
  19.  
  20.     })
  21.  
  22.     return render_to_response('list.html', context)
  23.  
  24. def Detail(request):
  25.     ShowImage = Image.objects.all()
  26.     ShowPinyin = Pinyin.objects.all()
  27.     ShowAudio = Audio.objects.all()
  28.     context = RequestContext(request, {
  29.         'ShowAudio': ShowAudio, 'ShowImage': ShowImage, 'ShowPinyin': ShowPinyin
  30.     })
  31.     return render_to_response('detail.html', context)
detail.html:
Expand|Select|Wrap|Line Numbers
  1. {% extends "base.html" %}
  2.  
  3. {% block title %}{{ item.title }}{% endblock %}
  4.  
  5. {% block content %}
  6.  
  7. <h2>{{ item.title }}</h2>
  8. <img src="{{ item.get_image_url }}" />
  9. {% if object.caption %}<p>{{ object.caption }}</p>{% endif %}
  10.  
  11. {% endblock %}
Thanks in advance!
Apr 2 '12 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.