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
from django import forms
from django.forms import ModelForm
from students.models import Student
class AwardForm(ModelForm):
class Meta:
model = Award
Models.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 }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.