Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango Form Preview
    primarykey
    data
    text
    <p>I'm trying to use django's FormPreview and I can't get it to work properly. Here's my code:</p> <p>forms.py</p> <pre><code>class MyForm(forms.ModelForm): status = forms.TypedChoiceField( coerce=int, choices=LIST_STATUS, label="type", widget=forms.RadioSelect ) description = forms.CharField(widget = forms.Textarea) stage = forms.CharField() def __init__(self, useradd=None, *args, **kwargs): super(MyForm, self).__init__(*args, **kwargs) self.fields['firm'].label = "Firm" class Meta: model = MyModel fields = ['status', 'description', 'stage'] class MyFormPreview(FormPreview): form_template = 'templates/post.html' preview_template = 'templates/review.html' def process_preview(self, request, cleaned_data): print "processed" def done(self, request, cleaned_data): print "done" # Do something with the cleaned_data, then redirect # to a "success" page. return HttpResponseRedirect('/') </code></pre> <p>urls.py</p> <pre><code>(r'^post/$', MyFormPreview(MyForm)), </code></pre> <p>post.html</p> <pre><code>&lt;form id = "post_ad" action = "" method = "POST" enctype="multipart/form-data"&gt; &lt;table&gt; {{form.as_table}} &lt;/table&gt; &lt;input type="submit" name="save" value="Post" /&gt; &lt;/form&gt; </code></pre> <p>When I go to /post/ I get the correct form and I fill it out. When I submit the form it goes right back to /post/ but but there are no errors (I've tried displaying {{errors}}) and the form is empty. None of my print statements execute. I'm not sure what I'm missing. Can anyone help me out? I can't find any documentation besides what's on the django site. </p> <p>Also, what's the "preview" variable called that I should use in my preview.html template? {{preview}} or do I just do {{form}} again? -- Answered below.</p> <p>I tried adding 'django.contrib.formtools' to my installed_apps in settings and I tried using the code from the default form templates from django.contrib as suggested below. Still, when I submit the form I go right back to the post template, none of my print statements execute :(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload