我正在使用v1.8学习django,正在尝试创建表单,但是提交不起作用,并且没有错误。 如果有人可以帮助我,那将非常好。谢谢
views.py
from django.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm
from django.shortcuts import render
def register(request):
if request.method == "POST" :
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
return redirect('/account')
else:
form = UserCreationForm()
args = {'form': form}
return render(request, 'polls/register.html', args)
register.htlm
{% block content %}
<form action="polls/register.html" method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="button">button</button>
</form>
{% endblock %}
答案 0 :(得分:1)
将button type
标签更改为input
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit">
</form>
{% endblock %}