我正在尝试在模板中打印模型属性值,但我得到" listOfArticles()正好接受1个参数(2个给定)"错误
views.py
def articles(request):
model = News.objects.order_by('-date')[: 5]
context = {
'models': model
}
return render(request, 'articles.html', context)
def listOfArticles(request):
models = News.objects.order_by('-date')[: 1]
context = {
'models': models
}
return render(request, 'articlesDetail.html', context)
urls.py
urlpatterns = patterns('',
url(r '^$', 'articles.views.articles', name = "latest_articles"),
url(r '^(\d+)$', 'articles.views.listOfArticles'),
)
models.py
class News(models.Model):
title = models.CharField("Title", max_length = 256)
author_Detail = models.CharField("Author", max_length = 128)
date = models.DateTimeField("Published Date")
class Meta:
verbose_name_plural = "News"
def __unicode__(self):
return self.title
答案 0 :(得分:1)
模式url(r '^(\d+)$', 'articles.views.listOfArticles'),
期望url (\d+)
中存在整数。将您的网址格式更改为相关内容,您可以继续进行。您可以执行r'^articles-list/$
:)