Monday, July 1, 2013

Views, Forms not working.

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,
    })

template datatables.html:
<!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>

models.py:
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()

and forms.py:
class DataTableForm(forms.ModelForm):
    class Meta:
        model = DataTable

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?
Cheers N //

--
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