my urls.py
from django.urls import path,include,re_path
from . import views
urlpatterns = [
path('', views.index,name='index'),
re_path(r'(?P<title> [\w]+)/$',views.article_details,name='details')
]
my views.py
def article_details(request,title):
return render(request, 'guestbook/article_detail.html')
my html:
<html lang="en">
<head>
<meta charset="UTF-8">
<h1><a href="{% url 'details' %}" > hello</h1>
<title>Title</title>
</head>
<body>
</body>
</html>
the error is NoReverseMatch at /guestbook/hello/ Error during template rendering
Reverse for 'details' with no arguments not found. 1 pattern(s) tried: ['guestbook\\/(?P<title>[\\w]+)/$']
What am I doing wrong here ? I can't seem to figure that out..please help
Try this in your html template- <h1><a href="{% url 'details' title="put_here_any_exiting_title_in_your_db" %}" > hello</h1>
Your details url expecting title parameter so you have to pass it there.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments