Function that works on Edit/Django but does not work on the/Django wiki. Why?

Asked

Viewed 80 times

1

I’m trying to make a feature to edit wikis.

When I enter Edit/Django it returns me all right, but when I enter the wiki/Django, for example, where you have the edit button, it returns this error:

Noreversematch at /wiki/Django Reverse for 'edit_page' with Arguments '('',)' not found. 1 Pattern(s) tried: ['Edit/(? P<page_title>[^/]+)$']

py views.:

def edit_page(request, page_title):
    content = util.get_entry(page_title)
    return render(request, "encyclopedia/edit.html", {
        "page_title": page_title,
        "content": content
    })

py.:

from django.urls import path, re_path

from . import views
app_name = "encyclopedia"

urlpatterns = [
    path("", views.index, name="index"),
    path("wiki/<str:page>", views.wiki_page, name="wiki_page"),
    path("create", views.add_entry, name="add_entry"),
    path("search", views.search, name="search"),
     path("edit/<str:page_title>", views.edit_page, name="edit_page")
]

wiki.html:

{% extends "encyclopedia/layout.html" %}

{% block title %}
    {{ title }}
{% endblock %}

{% block body %}
    <a href="{% url 'encyclopedia:edit_page' page_title %}">edit</a>
    {{ entry_content|safe }}

{% endblock %}

Edit.html:

{% extends "encyclopedia/layout.html" %}

{% block title %}
    {{ page_title }}
{% endblock %}

{% block body %}
    <form action="{% url 'encyclopedia:edit_page' page_title %}" method="POST">
        {% csrf_token %} 
        <h1>Edit Page</h1>
        <textarea name="edit-content" id="textarea-content">{{ content }}</textarea>
        <button class="btn btn-primary" id="save-edit" type="submit">save changes</button>
    </form>
{% endblock %}

Thanks in advance.

  • You have defined the function views.wiki_page? It’s being referenced in the url configuration, but I haven’t seen it in your views.py.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.