I have created a form without using the form model, but the form wouldn't submit any data and I dont get any error message.
The html file
<form action="{% url 'wiki:add_test' %}" method="post">
{% csrf_token %}
<div class="input_form">
<label class ="label_title" for="entry_title">Title:</label>
<input class="entry_title" type="text" name="entry_title" placeholder="Title">
</div>
<br>
<div class="input_form">
<div class="input_label"><label for="entry_content">Content:</label></div>
<div class="input_field">
<textarea class="entry_content" name="entry_content" id="" cols="5" rows="2"></textarea>
</div>
</div>
<div class="input_form">
<div class="title"></div>
<div class="input_button"><input type="button" value="Add Entry"></div>
</div>
</form>
The views.py
new_entry = ["Item1", "Item 2"]
def test1(request):
return render(request, "encyclopedia/display_test.html",{
"lists": new_entry
})
def add_test(request):
if request.method == "POST":
form1 = request.POST
print(request.POST['entry_title'])
list_item = form1['entry_title']
new_entry.append(list_item)
return HttpResponseRedirect(reverse("wiki:test1"))
return render(request, "encyclopedia/add.html")
The urls.py
from django.urls import path
from . import views
app_name = "wiki"
urlpatterns = [
path("", views.index, name="index"),
path("test1", views.test1, name="test1"),
path("add_test", views.add_test, name="add_test"),
]
I need help to know where I went wrong
question from:
https://stackoverflow.com/questions/65848266/how-do-i-solve-form-not-submiting-in-django 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…