我遇到此错误:
NoReverseMatch位于/ 未找到“ peliculas”的反向符号。 “ peliculas”不是有效的视图函数或模式名称。 请求方法:GET 要求网址:http://127.0.0.1:8000/ Django版本:2.1.2 异常类型:NoReverseMatch 异常值:
未找到“ peliculas”的反向符号。 “ peliculas”不是有效的视图函数或模式名称。 例外位置:_reverse_with_prefix,第622行中的C:\ Users \ Angel \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ django \ urls \ resolvers.py Python可执行文件:C:\ Users \ Angel \ AppData \ Local \ Programs \ Python \ Python37 \ python.exe python版本:3.7.1 Python路径:
['C:\ Users \ Angel \ Desktop \ Trabajos \ Videoclub \ videoclub_django', 'C:\ Users \ Angel \ AppData \ Local \ Programs \ Python \ Python37 \ python37.zip', 'C:\ Users \ Angel \ AppData \ Local \ Programs \ Python \ Python37 \ DLLs', 'C:\ Users \ Angel \ AppData \ Local \ Programs \ Python \ Python37 \ lib', 'C:\ Users \ Angel \ AppData \ Local \ Programs \ Python \ Python37', 'C:\ Users \ Angel \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages']
我只是不知道发生了什么
您可以在此处看到完整的代码:
https://github.com/AngelQuesada/videoclub_django
这是失败的部分(base_generic.html)
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="{% url 'index' %}">Inicio
<span class="sr-only">(current)</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'peliculas' %}">Peliculas</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Directores</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Actores</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Géneros</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://127.0.0.1:8000/admin/">Administración</a>
</li>
</ul>
</div>
我的urls.py文件:
from django.contrib import admin
from django.urls import path, include, re_path
from django.conf.urls import url
from . import views
app_name = "videoclub"
urlpatterns = [
path('', views.index, name="index"),
url(r'^peliculas/$', views.PeliculaListView.as_view(), name='peliculas'),
# url(r'^pelicula/(?P<pk>\d+)$', views.DetailPeliculaView.as_view(),
name='detalle-pelicula'),
]
预先感谢大家!
答案 0 :(得分:4)
您已在videoclubs
应用中为URL命名空间。因此,您不应该只使用{% url 'peliculas' %}