Noreversematch at /wiki/Edit/CSS/

Asked

Viewed 31 times

-2

Hello, I’m starting at Django and I’m two days trying to solve this problem. I’ve tried everything I’ve found from other people with the same problem and I can’t fix it. The code is this: My HTML sending the 'title' variable to urlpattern Edit:

{% block body %}
    {{ content|safe }}
    <a href="{% url 'edit' title %}"> Edit</a>
{% endblock %}

My url.py:

urlpatterns = [
    path("", views.index, name="index"),
    path("<str:title>/", views.entry, name="title"),
    path("search/", views.search, name="search"),
    path("newpage/", views.newpage, name="newpage"),
    path("edit/<str:title>/", views.edit, name="edit")
]

The view function it calls:

def edit(request, title):
    if request.method == "POST":
        form = NewEntry(request.POST)
        if form.is_valid():
            title = form.cleaned_data["title"]
            content = form.cleaned_data["textarea"]
            util.save_entry(title, content)
            return render(request, "encyclopedia/entry.html", {
                "content": markdown2.markdown(util.get_entry(title)), "form": NewSearchForm(), "title": title
            })
    else:      
        form2 = NewEntry(initial={'title': title, 'textarea': markdown2.markdown(util.get_entry(title))})
        return render(request, "encyclopedia/edit.html", {
                "title": title, "form": NewSearchForm(), "form2": form2
            })

Help me out, please!

1 answer

0

you have to put everything inside a form:

{% block body %}
    <form method="post">
      {{ content|safe }}
      <a href="{% url 'edit' title %}"> Edit</a>
    </form>
{% endblock %}

are using the "POST" method here if request.method == "POST":, and if you don’t post, it does nothing

  • The post method uses another html page, Edit.html which is rendered at the end of the get method. It did not work =/

  • where is the view that renders to the html that contains that button?

  • The button of the form that sends the request post?

  • the view that renders to the html that posted , which contains the content

  • &#xA;def entry(request, title):&#xA; if util.get_entry(title) == None:&#xA; return render(request, "encyclopedia/error.html", {&#xA; "form" : NewSearchForm()&#xA; })&#xA; else:&#xA; return render(request, "encyclopedia/entry.html", {&#xA; "content": markdown2.markdown(util.get_entry(title)), "title": title, "form": NewSearchForm()&#xA; })&#xA;

Browser other questions tagged

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