发生这种情况时,我试图在 Django 中实现动态 url
在我的 template.py 中,我添加了这一行
<a href="{% url 'Index' %}" role="button">Go to Index</a>
我的网址.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path("admin/", admin.site.urls),
path("", include("moviez.urls"))
]
我的moviez.urls.py
from django.urls import path
from .views import IndexView
app_name = "moviez"
urlpatterns = [
path("", IndexView, name="Index")
]
我认为这绝对应该可以工作,但它返回了这个错误
NoReverseMatch at /
Reverse for 'Index' not found. 'Index' is not a valid view function or pattern name.
你能帮我调试一下吗?
任何帮助将不胜感激!