Thursday, October 27, 2011

FormPreview and template variables

I'm a Django noob and fear the answer to my question is fairly obvious, but hoping someone can help.

I'm building an app that includes the same form on every page, with the content surrounding the form and the model instance to which the form data is tied dependent on a value passed in the URL. Works fine using the standard Form class and (URL, 'template.html', myapp.view) in URLconf, like so:

url(r'^listings/(?P<listing_id>\d+)/submit$', 'myapp.views.lister'),

With FormPreview, however, instead of calling the view in the URLconf, you're calling the subclass with the view functionality baked in.

url(r'^listings/(?P<listing_id>\d+)/submit$', PickFormPreview(PickForm)),

From what I can gather from the docs, FormPreview uses parse_params to pass values captured in the URL to state.self, which I believe is a dictionary. Unfortunately given my level of experience, I can't figure out from this barebones understanding how to customize my FormPreview subclass how to pass the listing_id captured in the URL to a template variable in my form.html template called by FormPreview. Do I somehow need to override parse_params? Or somehow pass state.listing_id? Or am I missing it entirely?

Any help much appreciated!

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

No comments:

Post a Comment