"""
form.is_valid():
model_instance.save()
model_instance.save()
"""
form.is_valid():
form.save()
2013/7/1 Nigel Legg <nigel.legg@gmail.com>
--Cheers N //The form shows fine (see image), but when I click the button it goes back to the index page, which isn't what I wanted to happen. Any thoughts on where I am going wrong?and forms.py:models.py:template datatables.html:So I have:views.py:
def datatables(request):
if request.method == 'POST':
form = DataTableForm(request.POST)
if form.is_valid():
model_instance.save()
return redirect('myapp/tabspec.html')
else:
form = DataTableForm()
return render(request, 'myapp/datatables.html', {
'form': form,
})
<!DOCTYPE HTML>
<html>
<header>
<title>Make Tables</title>
</header>
<!-- Action form -->
<form action="{% url "list" %}" method="post" enctype="multipart/formdata">{% csrf_token %}
<p> {{ form.datFile.label_tag }} {{ form.datFile }} </p>
<p> {{ form.structFile.label_tag }} {{ form.structFile }} </p>
<p> {{ form.bannerVar.label_tag}} {{ form.bannerVar }} </p>
<p> {{ form.stubVar.label_tag}} {{ form.stubVar }} </p>
<p> {{ form.stubNets.label_tag }} {{ form.stubNets }} </p>
<p><input type="submit" value="Confirm selections" /></p>
</body>
</html>
class DataTable(models.Model):
datFile = models.CharField(max_length = 200)
structFile = models.CharField(max_length = 200)
bannerVar = models.CharField(max_length = 50)
stubVar = models.CharField(max_length = 50)
stubNets = models.BooleanField()
class DataTableForm(forms.ModelForm):
class Meta:
model = DataTable
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
Mário Idival
Twitter : @marioigd
Facebook: mario.idival
User Linux : #554446
Skype: marioidival
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment