NoReverseMatch at / Reverse for 'movies-detail' for 'movie-detail' for '('Dark',)'找不到。尝试了 1



我想传递2个url标签,但在中出现错误

{% for movie in movies %}
<div class="row">
<div class="col-md-7">
<a href="{% url 'movies-detail' movie.name %}">
<img class="rounded mb-3 mb-md-0"  src="{{ movie.image.url }}" height="200" width="400" alt="">
</a>
</div>
<div class="col-md-5">
<h2><a class="article-title" href="{% url 'movies-detail' movie.name movie.id %}">{{ movie.name }} {{ movie.id }}</a></h2>
<h4 class="text-muted">Released Date : {{ movie.date_released|date:"F d, Y " }}</h4>
<h4 class="article-title" >Producer : {{ movie.producer }}</h4>
<h4 class="article-title" >Director : {{ movie.director }}</h4>
</div>
</div>
<p> {% ratings movie %}</p>
<hr>
{% endfor %}

想要在urls.py中接收并显示

url模式=[

path('about/', AboutView.as_view(), name='blog-about'),
path('user/<str:username>/', UserPostListView.as_view(), name='user-post'),
path('post/<int:pk>/', PostDetailView.as_view(), name='post-detail'),
path('post/new/<str:name>/', PostCreateView.as_view(), name='post-create'),
path('', MoviesListView.as_view(), name='blog-home'),
path('<str:name>/<int:id>/',MoviesDetailListView.as_view(), name='movies-detail'),
path('post/<int:pk>/update/', PostUpdateView.as_view(), name='post-update'),
path('post/<int:pk>/delete/', PostDeleteView.as_view(), name='post-delete'),

]

with arguments '('Dark',)'告诉您,您只提供了名称,而没有提供id。

movie.id添加到第一个链接。

<a href="{% url 'movies-detail' movie.name movie.id %}">

指向movies-detail页面的第二个链接看起来已经很准确了。

您的错误是由于第一个标记<a href="{% url 'movies-detail' movie.name %}">引起的。您只提供了一个位置参数,其中需要两个。

为这个特定的url标记添加一个额外的url,但使用一个单独的name

urls.py

urlpatterns = [path('about/', AboutView.as_view(), name='blog-about'),
path('user/<str:username>/', UserPostListView.as_view(), name='user-post'),
path('post/<int:pk>/', PostDetailView.as_view(), name='post-detail'),
path('post/new/<str:name>/', PostCreateView.as_view(), name='post-create'),
path('', MoviesListView.as_view(), name='blog-home'),
path('<str:name>/<int:id>/',MoviesDetailListView.as_view(), name='movies-detail'),
path('<str:name>/',MoviesDetailListView.as_view(), name='movies-detail-name'),
path('post/<int:pk>/update/', PostUpdateView.as_view(), name='post-update'),
path('post/<int:pk>/delete/', PostDeleteView.as_view(), name='post-delete'),
]

相关内容

最新更新