LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   django: Is it possible to create a form "on the fly"? (https://www.linuxquestions.org/questions/programming-9/django-is-it-possible-to-create-a-form-on-the-fly-907660/)

eantoranz 10-11-2011 05:24 PM

django: Is it possible to create a form "on the fly"?
 
Hi!

I'm wondering if it's possible to create a form on the fly? I mean, instead of having a class extend a form defining the fields in the form, is it possible to create it manually so that the form code can be retrieved for an HTML page and checked on submittal?

theNbomr 10-13-2011 03:24 PM

Since this has gone unanswered for a few days, I'll take a shot, with the proviso that I'm a full-on Django newbie.

Since you can return anything you want as an HttpResponse object in your views.py module, I'll say 'sure'. Whatever HTML your view class can generate should work. Whether this is considered good form (bad pun intended) is another matter. But really, you can also use iteration in templates, so I don't understand why that wouldn't be just as good; probably even better.

--- rod.

dugan 10-13-2011 03:32 PM

I'm going to say yes, even though I don't understand the following:

Quote:

is it possible to create it manually so that the form code can be retrieved for an HTML page and checked on submittal?
You can obviously create a form without using the Form class (just put the form and its fields in a template). You also have the freedom to return any string you want to from a Django view. And if you're summitting the form via POST, then the POST data will be available to your views.

eantoranz 10-13-2011 03:42 PM

I mean using a form to create the html code for the given for and be able to use the form to do the checks when the form is "POSTED", so to speak. And it can be done... or at least, it has worked for me. Check http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/


All times are GMT -5. The time now is 11:14 PM.