Reverse for 'edit' with keyword arguments '{'title': 'HTML'}' not found

Viewed 58

I'm running a program to create a wikipedia style website using python and the django framework. I'm running into an issue where I have a link to edit the wiki page on the entry pages. When the page tries to render I get the error message in the title of this post. I'm not sure why it's not finding the edit page, I think I might have a typo somewhere but I'm not finding it. Any help here would be greatly appreciated!

URLS.py

urlpatterns = [
    path("", views.index, name="index"), 
    path("error", views.error, name="error"),
    path("newPage", views.newPage, name="newPage"),
    path("random", views.random, name="random"),
    path("edit", views.edit, name="edit"),
    path("<str:entry>", views.markdown, name="entry")
    
    
]

entry.html

{% block nav %}
    <div>
        <a href="{% url 'edit' title=entry %}" method="GET">Edit Page</a>
    </div>
{% endblock %}

views.py entry function

def edit(request, title):
    content = util.get_entry(title)
    return render(request, "encyclopedia/newPage.html", {
        "title": title, 
        "content": content
    })
1 Answers

Your edit URL needs a parameter to specify the entry in the URL, so:

#                 ↓ url parameter
path('edit/<str:title>/', views.edit, name='edit'),

If the title can contain a slash, you need to use the <path:…> path converter [Django-doc]:

#                  ↓ url parameter
path('edit/<path:title>/', views.edit, name='edit'),
Related