我试图在维基页面上放置一个编辑按钮,但它给了我这个错误:
NoReverseMatch at /wiki/CSS Reverse for 'edit_pagina' with no arguments not found. 尝试了 1 种模式:['edit/(?P[^/]+)$']
urls.py:
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:editPage>", views.edit_page, name="edit_page")
]
views.py:
def get_entry(title):
"""
Retrieves an encyclopedia entry by its title. If no such
entry exists, the function returns None.
"""
try:
f = default_storage.open(f"entries/{title}.md")
return f.read().decode("utf-8")
except FileNotFoundError:
return None
def edit_page(request, editPage):
content = util.get_entry(editPage)
return render(request, "encyclopedia/edit.html", {
"page_title": editPage,
"content": content
})
编辑.html:
{% extends "encyclopedia/layout.html" %}
{% block title %}
{{ page_title }}
{% endblock %}
{% block body %}
<form action="{% url 'edit_page' %}" 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 %}
POPMUISE
吃鸡游戏
MYYA
相关分类