[英]How to solve NoReverseMatch at / (Error during template rendering) in django 3.2?
Here is the screenshots of error i am getting.这是我收到的错误截图。
and和
App Name is greeting_app Now greeting_app/urls.py has the following code应用名称为greeting_app 现在greeting_app/urls.py 有如下代码
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name="home"),
path('about/<int:id>/', views.about, name="about"),
]
greeting_app/views.py has the following code greeting_app/views.py 有以下代码
from django.shortcuts import render, HttpResponse
from .models import basicinformation
# Create your views here.
def home(request):
information = basicinformation.objects.all()
return render(request, 'index.html', {"info":information})
def about(request, id):
data = basicinformation.objects.get(id=id)
return render(request, 'about.html', {"data":data})
templates/index.html has the following code. templates/index.html 有以下代码。 I have included only the url part in index.html file.
我只在 index.html 文件中包含了 url 部分。
<a href="{% url "about" data.id %}">Description</a>
data.id
does not contain an ID. data.id
不包含 ID。 From the error message it contains ('',)
(or possibly (",)
- it's hard to tell from an image. Please don't use images!).从错误消息中它包含
('',)
(或可能是(",)
- 很难从图像中分辨出来。请不要使用图像!)。
You do for all in info
, then reference all
in every other template line, then suddenly try and use data.id
.您
for all in info
执行for all in info
,然后在所有其他模板行中引用all
,然后突然尝试使用data.id
。
Since you haven't posted your whole template, it's hard to tell, but I suspect you want to use all.id
in your URL here, and not data.id
.由于您尚未发布整个模板,因此很难说,但我怀疑您想在此处的 URL 中使用
all.id
,而不是data.id
。
app_name=“ greeting_app” app_name="问候应用程序"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.