how to use forms in django-cms?

Maverick picture Maverick · Mar 26, 2011 · Viewed 15.5k times · Source

I am an absolute novice to django-cms. I have gone through the tutorial and configured it exactly the same as mentioned in the documentation. Now, I have to build an application which uses a form to upload products.

I dont have a clue as to how to move ahead with it. I want to start it with simple forms as if now, say, a username and password textbox kind of. How can I use django forms in the django-cms page? I have snippet plugin enabled in it too. I need some guidance for this.

Any suggestions plsss. thanks

Answer

ojii picture ojii · Mar 26, 2011

Actually the solution proposed by bennylope is not the preferred way to do it, since using request.POST in a plugin can have very bad side effects (eg: what if the same plugin is twice on a page? Or what if there's multiple plugins waiting for POST data on the same page? Those plugins would confuse each other when there's a POST to that page).

So the preferred way is:

  • Make a CMSPlugin as described by bennylope to render the form.
  • Make the form post to a statically hooked view (or a apphooked view), if the POST is successful, redirect to the page again if you want.