所以我正在做Django实践项目教程并且走得很远。
我有这段代码:
def get_absolute_url(self):
return ('coltrane_entry_detail', (), {'year': self.pub_date.strftime("%Y"),
'month': self.pub_date.strftime("%b").lower(),
'day': self.pub_date.strftime("%d"),
'slug': self.slug })
get_absolute_url = models.permalink(get_absolute_url)
我收到缩进错误。
如果我缩进比获得工作/ weblog / url但是如果我点击“阅读更多”链接我总是登陆同一页面/ weblog /而不是/ weblog / date / article。
如果你知道这个教程,也许你知道错误,如果不是这里是所有文件:
from django.conf.urls.defaults import *
from Myproject.views import *
from django.views.generic.simple import direct_to_template
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
#Coltrane Project URlpatterns:
(r'^search/$', 'MyProject.search.views.search'),
(r'^weblog/$', include('coltrane.urls')),
from django.conf.urls.defaults import *
from coltrane.models import Entry
entry_info_dict = {
'queryset': Entry.objects.all(),
'date_field': 'pub_date',
}
#Coltrane Project URlpatterns:
urlpatterns = patterns('django.views.generic.date_based',
(r'^$', 'archive_index', entry_info_dict, 'coltrane_entry_archive_index'),
(r'^(?P<year>\d{4})/$', 'archive_year', entry_info_dict, 'coltrane_entry_archive_year'),
(r'^(?P<year>\d{4})/(?P<month>\w{3})/$', 'archive_month', entry_info_dict, 'coltrane_entry_archive_month'),
(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/$', 'archive_day', entry_info_dict, 'coltrane_entry_archive_day'),
(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', 'object_detail', entry_info_dict, 'coltrane_entry_detail'),
)
import datetime
from django.contrib.auth.models import User
from django.db import models
from markdown import markdown
from tagging.fields import TagField
class Category(models.Model):
title = models.CharField(max_length=250, help_text='Maximum 250 characters.')
slug = models.SlugField(unique=True, help_text='This is the shortname that is created. Must be unique!')
description = models.TextField()
class Meta:
ordering = ['title']
verbose_name_plural = "Categories"
def __unicode__(self):
return self.title
def get_absolute_url(self):
return "/categories/%s/" %self.slug
class Entry(models.Model):
LIVE_STATUS = 1
DRAFT_STATUS = 2
HIDDEN_STATUS = 3
STATUS_CHOICES = (
(LIVE_STATUS, 'Live'),
(DRAFT_STATUS, 'Draft'),
(HIDDEN_STATUS, 'Hidden'),
)
#Core Fields.
title = models.CharField(max_length=250, help_text='Maximum 250 characters.')
excerpt = models.TextField(blank=True, help_text='A short summary of the entry. Optional!')
body = models.TextField()
pub_date = models.DateTimeField(default=datetime.datetime.now)
#Fields to store generated HTML.
excerpt_html = models.TextField(editable=False, blank=True)
body_html = models.TextField(editable=False, blank=True)
#Metadata
author = models.ForeignKey(User)
enable_comments = models.BooleanField(default=True)
featured = models.BooleanField(default=False)
slug = models.SlugField(unique_for_date='pub_date')
status = models.IntegerField(choices=STATUS_CHOICES, default=LIVE_STATUS, help_text="Only entries with live status will be publicly displayed")
#Categorization
categories = models.ManyToManyField(Category)
tags = TagField(help_text="Separate tags with spaces.")
class Meta:
ordering = ['pub_date']
verbose_name_plural = "Entries"
def __unicode__(self):
return self.title
def save(self, force_insert=False, force_update=False):
self.body_html = markdown(self.body)
if self.excerpt:
self.excerpt_html = markdown(self.excerpt)
super(Entry, self).save(force_insert, force_update)
def get_absolute_url(self):
return ('coltrane_entry_detail', (), {'year': self.pub_date.strftime("%Y"),
'month': self.pub_date.strftime("%b").lower(),
'day': self.pub_date.strftime("%d"),
'slug': self.slug })
get_absolute_url = models.permalink(get_absolute_url)
答案 0 :(得分:0)
看到上面的评论,我发现了我的错误。我认为解决我自己问题的唯一方法就是回答它。