On Nov 4, 10:32 pm, octopusgrabbus <old_road_f...@verizon.net> wrote:
> I have a forms class in forms.py
>
> from django import forms
>
> class ReadSnapForm(forms.Form):
>     cycle = forms.CharField(max_length=1)
>     message = forms.CharField(widget-forms.Textarea,required=False)
>
> Here is the form that uses the class
> {% extends "base.html" %}
>
> <html>
> <head>
>     <h1>Enter Billing Cycle</h1>
> </head>
> <body>
>         <h1>Enter Billing Cycle</h1>
>         {% if form.errors %}
>         <p style="color: red;">
>             Please correct the error{{ form.errors|pluralize }} below.
>         </p>
>         {% endif %}
>
>         <form action="" method="post"> {% csrf_token %}
>             <table>
>                 {{ form.as_table }}
>             </table>
>             <input type="submit" value="Snap Read">
>         </form>
> </body>
> </html>
>
> Here's the code in views.py
>
> from forms import ReadSnapForm
>
> def read_snap(request):
>     if request.method == 'POST':
>         form = ReadSnapForm(request.POST)
>         if form.is_valid():
>             cleaned_data = form.cleaned_data
>             return HttpResponseRedirect('/read_snap/
> after_read_snap.html')
>     else:
>         form = ReadSnapForm()
>
>     return render_to_response('/read_snap/read_snap.html', {'form':
> form})
>
> I can get to the form through an href on a main page, but nothing
> displays on the form.
>
> What am I doing wrong?

There's a typo in the message field declaration, but presumably that's
not actually in your code, as it wouldn't even compile, so I'm
assuming it's just a copy/paste issue.

The actual issue is nothing to do with forms - it's in your template.
You're extending base.html, but not providing any {% block %} elements
to actually insert into that parent template. As a result, the parent
is just displayed, without any of the child data.

Either remove the {% extends %} tag, or provide the proper {% block %}
elements that override blocks in your parent, and put the form HTML in
there.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to