gpt4 book ai didi

python - listOfArticles() 只接受 1 个参数(给定 2 个参数)

转载 作者:太空宇宙 更新时间:2023-11-03 17:11:02 25 4
gpt4 key购买 nike

我正在尝试在模板中打印模型属性值,但收到“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

最佳答案

模式url(r '^(\d+)$', 'articles.views.listOfArticles'),期望 url (\d+) 中有一个整数。将您的网址模式更改为相关的内容,然后您就可以继续了。你可以做类似 r'^articles-list/$ 的事情:)

关于python - listOfArticles() 只接受 1 个参数(给定 2 个参数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34082373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com