object_detail并(),而只输入了一个关键字参数“查询集”多个值(object_detai

2019-10-28 15:12发布

from django.conf.urls.defaults import *
from django.conf import settings
from Website.Blog.models import Post
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

index = {
            'queryset': Post.objects.all(),
            'date_field': 'created_on',
            'template_name': 'index.html',
            'num_latest': 5
        }

post =  {
            'template_name': 'index.html',
            'queryset': Post.objects.all(), # only here, what could be wrong?
            'slug': 'slug',
        }

urlpatterns = patterns('',
    # Example:
    url(r'^$', 'django.views.generic.date_based.archive_index', index, name='index'),
    url(r'^post/(\S+)/$', 'django.views.generic.list_detail.object_detail', post, name='post'),

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
    # to INSTALLED_APPS to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls))
)


if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^css/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
        (r'^images/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.IMAGES_ROOT, 'show_indexes': True})
    )

Answer 1:

所述object_detail观点queryset作为第一位置参数。 因此,相匹配的值(\S+)在您的正则该URL被解释为查询集ARG,这是与你逝去的POST字典kwarg冲突。

如果你想发送的object_id作为URL匹配的元素,你需要使用一个命名组:

url(r'^post/(?P<object_id>\S+)/$' ...


Answer 2:

您需要添加?:到你不想上视图功能传递组(括号内)。 像这样:

url(r'^post/(?:\S+)/$', 'django.views.generic.list_detail.object_detail', post, name='post'),

请参见本文的详细信息: http://www.b-list.org/weblog/2007/oct/14/url-patterns/



文章来源: object_detail() got multiple values for keyword argument 'queryset' while inputting only one