[Answered ]-Reverse for 'entrypage' with no arguments not found. 1 pattern(s) tried: ['wiki/(?P<title>[^/]+)$']

1👍

When you make a redirect to entrypage, you need to specify the title, so:

from django.shortcuts import redirect

def add_page(request):
    if request.method == "POST":
        form = AddPageForm(request.POST)
        entries = util.list_entries()
        if form.is_valid():
            title = form.cleaned_data['title']
            content = form.cleaned_data['content']
            util.save_entry(title, content)
        
            for entry in entries:
                if title.upper() == entry.upper():
                    return render(request, "encyclopedia/errorpage.html")
            #                                   specify title ↓
            return redirect('encyclopedia:entrypage', title=title)
    # …

I would also strongly advise to make use of a database, and not fetch all entries from the utility: a database is optimized to search effective, whereas accessing the list of files takes linear time to search. If you define a database model, you can add db_index=True [Django-doc] to build an index which can boost searching enormously.

Leave a comment