开发者

django tutorial stuck

So I am doing the Django Practical Projects Tutorial and came very far.

I have this code:

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)

I get an Indentation Error.

If I indent than I get a working /weblog/ url but if I click on the "Read more" Links I always land on the same page /weblog/ and not /weblog/date/article.

If you know the tutorial, maybe you know the error if not here is all the files:

urls project:

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')),

Urls Coltrane:

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'),
)

Model:

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)


See the comments above, I found my error. I think the only way to close my own question is to answer it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜