-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!
The post method uses another html page, Edit.html which is rendered at the end of the get method. It did not work =/
– Igão
where is the view that renders to the html that contains that button?
– Pedro Mariz
The button of the form that sends the request post?
– Igão
the view that renders to the html that posted , which contains the
content
– Pedro Mariz

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

– Igão