[SOLVED] django: Is it possible to create a form "on the fly"?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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?
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.
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.
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/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.