I am working on CS50 Web Development on the lesson of Django.
I want to pass a string from view.py to HTML as the URL link
here is the view.py
def randompage(request, name):
random_page = random.choice(util.list_entries())
return render(request, "encyclopedia/layout.html", {
"random_page": random_page})
and this is the HTML page
<a href="{% url 'randompage' random_page %}"> Random Page </a>
the urls.py
urlpatterns = [
path("", views.index, name="index"),
path("wiki/<str:name>", views.title, name= "title"),
path("wiki/", views.randompage, name= "randompage"),
path("searchresult", views.searchresult, name= "searchresult"),
path("newpage", views.newpage, name= "newpage")
]
the error code is
NoReverseMatch at / Reverse for 'randompage' with arguments '('',)' not found. 1 pattern(s) tried: ['wiki/$']
I know I shall you templatetag URL, but I don't really understand how it works and I cant find anyone have a similar situation with me.