[英]Initial Value with Form not working
I have a form with an initial value, but I can't get the initial value to show.我有一个带有初始值的表单,但无法显示初始值。
def addaward(request):
if request.method == "POST":
form = AwardForm(request.POST)
form.save()
else:
form = AwardForm(initial={'title': 'hi!'})
return render_to_response('award.html',{'form': AwardForm}, context_instance = RequestContext(request))
What is really strange is when I delete the line with真正奇怪的是当我删除行时
form = AwardForm(initial={'title': 'hi!'})
the form still shows with no error messages.该表格仍然显示没有错误消息。
Forms.py Forms.py
from django import forms
from django.forms import ModelForm
from students.models import Student
class AwardForm(ModelForm):
class Meta:
model = Award
Models.py模型.py
class Award(models.Model)
date = models.DateTimeField(auto_now_add = True, editable = True)
student = models.ForeignKey('Student')
type = models.CharField('Category', max_length = 30)
title = models.CharField('Title of Award', max_length = 30)
description = models.TextField('Description')
Any ideas would be great.任何想法都会很棒。 Thank you!
谢谢!
this:这个:
{'form': AwardForm}
should be:应该:
{'form': form }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.