【发布时间】:2014-04-15 09:54:35
【问题描述】:
我一直在尝试在我的模型中对 CharField 进行 slugify。我遵循this 教程,但我只设法得到一个数据库错误。 “列article_article.slug 不存在。我知道South 和migrations 但我没有正确使用它。基本上我有一个博客应用程序,每个帖子都由一个ID 号标识。我想slugify每篇博文的标题。
这是我的意见.py
def article(request, article_id =1):
return render_to response('article.html', {'article':Article.Objects.get(id=article_id)}, context_instance=ResquestContext(request))
这是我的models.py
class Article(models.Model):
title = models.CharField(max_length=30) #<--want to slugify this
body = models.TextField()
pub_date = models.DateTimeField('date published')
likes = models.IntegerField(default = 0)
def __unicode__(self):
return self.title
这是我的 urls.py
...
url(r'^get/(?P<article_id>\d+)/$', 'article.views.article'),
...
这是我的文章.html
...
<a id = "title2" href="articles/get{{ article.id }} /"> {{ article.title }} </a>
...
【问题讨论】:
-
可能重复:stackoverflow.com/questions/837828/…请先搜索。您必须创建一个字段来存储 slug,因此您的错误。
-
你确实没有名为
slug的字段。