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})
)
Q
object_detail() a plusieurs valeurs pour l'argument mot-clé « queryset » lors de la saisie une seule
0
A
Répondre
1
La vue object_detail
a queryset
comme premier argument de position. Ainsi, la valeur qui correspond à (\S+)
dans votre expression rationnelle pour cet URL est interprétée comme l'argument queryset, qui est en conflit avec le kwarg que vous transmettez dans le dictionnaire POST.
Si vous essayez d'envoyer object_id comme l'élément correspondant dans l'URL, vous aurez besoin d'utiliser un groupe nommé:
url(r'^post/(?P<object_id>\S+)/$' ...
0
Vous devez ajouter ?:
aux groupes (entre parenthèses) que vous ne voulez pas être transmis à la fonction de vue. Comme ceci:
url(r'^post/(?:\S+)/$', 'django.views.generic.list_detail.object_detail', post, name='post'),
Voir cet article pour plus d'informations: http://www.b-list.org/weblog/2007/oct/14/url-patterns/
Je suis en train d'envoyer une limace –