Monday, July 1, 2013

Re: Views, Forms not working.

Tried that, still going back to the index page.



On 1 July 2013 15:33, Mário Idival <marioidival@gmail.com> wrote:
"""
form.is_valid():
            model_instance.save()

"""

form.is_valid():
    form.save()




2013/7/1 Nigel Legg <nigel.legg@gmail.com>
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.
 
 



--
Mário Idival

Twitter @marioigd
Facebookmario.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.
 
 

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