我无法验证我的django表单。我的表单没有验证。任何人都可以请检查我的代码,并指出我的错在哪里。这里是我的代码。我的Django表单无法验证
models.py-
from django.db import models
classcommentbox
(models.Model) :
box=models.CharField(max_length=
50)
forms.py-
from django.forms import ModelForm
from . models import commentbox
class commentboxForm(ModelForm):
class Meta:
model=commentbox
fields=['box']
views.py-
from django.http import HttpResponse
from . models import commentbox
from . forms import commentboxForm
def submit(request):
if request.method=="POST":
form=commentboxForm(request.
POST)
if form.is_valid():
return HttpResponse('valid')
else:
return HttpResponse('not
Valid')
else:
return HttpResponse("error")
模板 -
<form action="{% url 'poll:submit'
%}"method="POST">
{%csrf_token%}
<label for"comment"> say something:
</label>
<textarea class="form-control"
rows="3" id="comment"> </textarea>
<button type="button"> submit
</button>
</form>
非常感谢。它现在工作。 :) – user8174655