我無法驗證我的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