[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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.