Я пробираюсь через учебник по Django webmonkey и в настоящее время застрял в уроке 4, доступном здесь http://www.webmonkey.com/2010/02/Use_Templates_in_Django/.
Моя проблема связана с шаблоном подробностей блога, когда я нажимаю на ссылку в моем блоге /Страница list.html для просмотра сведений о записи Я получаю страницу не найдена (404).
Это именно та ошибка, которую я вижу:
Page not found (404)
Request Method: GET
Request URL:http://127.0.0.1:8000/2010/dec/17/welcome-my-blog/
Using the URLconf defined in djangoblog.urls, Django tried these URL patterns, in this order:
^admin/(.*)
^blog/
^tags/(?P<slug>[a-zA-Z0-9_.-]+)/$
The current URL, 2010/dec/17/welcome-my-blog/, didn't match any of these.
Это мои файлы url.py, а также мой models.py, я не опубликовал свой админ, представления тегов или настройкино я могу, если это поможет.
djangoblog \ urls.py
# This also imports the include function
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/(.*)', admin.site.root),
(r'^blog/', include('djangoblog.blog.urls')),
(r'^tags/(?P<slug>[a-zA-Z0-9_.-]+)/$', 'djangoblog.tag_views.tag_detail'),
)
djangoblog \ blog \ urls.py
from django.conf.urls.defaults import *
from djangoblog.blog.models import Entry
from tagging.views import tagged_object_list
info_dict = {
'queryset': Entry.objects.filter(status=1),
'date_field': 'pub_date',
}
urlpatterns = patterns('django.views.generic.date_based',
(r'(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(?P<slug>[-w]+)/$',
'object_detail', dict(info_dict, slug_field='slug',template_name='blog/detail.html')),
(r'^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(?P<slug>[-w]+)/$',
'object_detail', dict(info_dict, template_name='blog/list.html')),
(r'^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/$',
'archive_day',dict(info_dict,template_name='blog/list.html')),
(r'^(?P<year>d{4})/(?P<month>[a-z]{3})/$','archive_month', dict(info_dict, template_name='blog/list.html')),
(r'^(?P<year>d{4})/$','archive_year', dict(info_dict, template_name='blog/list.html')),
(r'^$','archive_index', dict(info_dict, template_name='blog/list.html')),
)
djangoblog \ blog \ models.py .
from django.db import models
from django.contrib.syndication.feeds import Feed
from django.contrib.sitemaps import Sitemap
import markdown
from tagging.fields import TagField
from tagging.models import Tag
class Entry(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(
unique_for_date='pub_date',
help_text='Automatically built from the title.'
)
body_html = models.TextField(blank=True)
body_markdown = models.TextField()
pub_date = models.DateTimeField('Date published')
tags = TagField()
enable_comments = models.BooleanField(default=True)
PUB_STATUS = (
(0, 'Draft'),
(1, 'Published'),
)
status = models.IntegerField(choices=PUB_STATUS, default=0)
class Meta:
ordering = ('-pub_date',)
get_latest_by = 'pub_date'
verbose_name_plural = 'entries'
def __unicode__(self):
return u'%s' %(self.title)
def get_absolute_url(self):
return "/%s/%s/" %(self.pub_date.strftime("%Y/%b/%d").lower(), self.slug)
def save(self):
self.body_html = markdown.markdown(self.body_markdown, safe_mode = False)
super(Entry, self).save()
def get_previous_published(self):
return self.get_previous_by_pub_date(status__exact=1)
def get_next_published(self):
return self.get_next_by_pub_date(status__exact=1)
def get_tags(self):
return Tag.objects.get_for_object(self)
Если есть какие-либо другие файлы, которые могут помочь, я могу их предоставить.Моя структура файла приведена ниже:
Структура файла
C:\Workspaces\python\djangoblog
urls.py
tag_views.py
settings.py
manage.py
djangoblog.db
admin.py
__init__.py
templates
blog
detail.html
list.html
tags
detail.html (empty)
list.html (empty)
base.html
tagging
markdown
blog
__init__.py
admin.py
models.py
tests.py
urls.py
views.py
Редактировать: (из комментария к ответу Джоша)
404 по адресу: блог/ dec / 17 / welcome-my-blog /:
^admin/(.*)
^blog/ (?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(? P<slug>[-w]+)/$
^blog/ ^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(? P<slug>[-w]+)/$
^blog/ ^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/$
^blog/ ^(?P<year>d{4})/(?P<month>[a-z]{3})/$
^blog/ ^(?P<year>d{4})/$
^blog/
^$ ^tags/(?P<slug>[a-zA-Z0-9_.-]+)/$
The current URL, blog/2010/dec/17/welcome-my-blog/, didn't match any of these.