Reputation: 1
I keep getting an error saying that my BundleForm has no attribute is_valid. I double and triple checked and my BundleForm is associated with a model, specifically my Bundle model. I can't figure out why else I would be getting this error. Any comments/input greatly welcomed!
models.py
class Bundle(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
user_profile = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
def __str__(self):
return self.name
forms.py
class BundleForm(forms.ModelForm):
name = forms.CharField(
help_text='Enter mission name. Change to hidden unless mouse over. ',
initial='bundle_name',
required=True,
max_length=50,
)
class Meta:
model = Bundle
fields = ('name',)
views.py
def new_bundle(request):
form1 = BundleForm()
if request.method == 'POST':
form1 = BundleForm(request.POST)
if form1.is_vaild():
bundle = form1.save(commit=True)
return render(request, 'build_a_bundle/new_bundle.html', {'bundle':bundle})
else:
return HttpResponse('Form 1 Error')
return render(request, 'build_a_bundle/new_bundle.html', {'form1':form1})
Upvotes: 0
Views: 958
Reputation: 21
This is a syntax error. I've made the same mistake too.
.is_vaild()
.is_valid()
Upvotes: 1
Reputation: 5578
There's a syntax error, change if form1.is_vaild():
to : if form1.is_valid():
.
Upvotes: 4