0
所以我正在做的Django實用項目教程,並走了很遠。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)
我得到一個錯誤壓痕。
如果我縮進比我得到一個工作/網絡日誌/網址,但如果我點擊「閱讀更多」鏈接,我總是在同一頁/博客/而不是/博客/日期/文章。
如果你知道教程,也許你知道的錯誤,如果不是這裏的所有文件:
網址項目:
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')),
的url雷恩:
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)
使用正確的縮進!單個空間不足以查看是否錯誤,因此IndentationError。使用四個空格。 – 2010-08-03 14:29:35
如果你指的: 高清get_absolute_url(個體經營): 回報(「coltrane_entry_detail」 事實並非如此,它只是在這裏顯示有一個縮進在我真正的代碼,它已收到回報 – MacPython 2010-08-03 14:49:40
4空間找到了我的錯誤。 :這是在urls.py: (R '^博客/ $' 而不是 (R '^博客/' – MacPython 2010-08-03 15:13:22