我正在尝试重定向到我打算在创建一个页面后作为对象主页实现的页面。 views.py
from django.shortcuts import render, get_object_or_404
from f.models import Post
def list(request):
post = Post.objects.all()
context = {
'post': post,
}
return render(request, 'list.html', context)
def detail(request, id=None):
Post = get_object_or_404(post, id=id)
context = {
'Post': Post,
}
return render(request, 'detail.html', context)
url.py
urlpatterns = [
url(r'^$', views.list, name='list'),
url(r'^(?P<id>[0-9]{1,3})$', views.list, name='detail'),
]
和我的错误
Django Version: 1.9.10
Exception Type: TypeError
Exception Value:
list() got an unexpected keyword argument 'id'
Python Version: 3.5.2
答案 0 :(得分:2)
看看路线:
url(r'^(?P<id>[0-9]{1,3})$', views.list, name='detail'),
您要将详细信息网址发送到列表视图views.list
,而不是详细信息视图views.detail
。
另外,最好为列表视图选择不同的名称,因为list
会影响内置名称list
。