Django Dynamic Form

Create dynamic form for render as an empty web form.

from django import forms
form_config = {'login':'CharField', 'email':'EmailField', 'active':'BooleanField'}
dynamic_form = forms.Form()
for key in form_config.keys():
dynamic_form.fields.insert(-1, key, getattr(forms, form_config.get(key))())
print dynamic_form.as_table()

output

Create dynamic form and validate the input data.

from django import forms
form_config = {'login':'CharField', 'email':'EmailField', 'active':'BooleanField'}
dynamic_form = forms.Form()
dynamic_form.__init__({'login':'cwt', 'email':'cwt.bashell.com', 'active':True})
for key in form_config.keys():
dynamic_form.fields.insert(-1, key, getattr(forms, form_config.get(key))())

Validation

>>> dynamic_form.is_valid()
<<< False

>>> dynamic_form.errors
<<< {'email': [u'Enter a valid e-mail address.']}

Note that when you want to validate the data, you must initialize dynamic_form with the input data before insert the fields.

Comments:

The manner in which the subject is explained is simply spectacular. I like some of the comments as well.

Django Dynamic forms are outdated. I just use WordPress plugins and the like for anything dynamic.

I always post relevant comments and follow-up to see if the blog owner has replied to my comment.

Attractive design and very impressive content.

I really loved reading your blog. It was very well authored and easy to understand. Unlike additional blogs I have read which are really not good. I also found your posts very interesting. In fact after reading, I had to go show it to my friend and he enjoyed it as well!

Very informative review. I really appreciate how ways were laid. Very interesting.

very good web site, There's no doubt that the content you develop could possibly help to any or all who see clearly. I have to loose time waiting for your posting at a later date.

I do think this is usually a good site, and I am super engaged you just read this. I'm guessing you'll can supply additional information which can be of great help for most. thank you

This is the amazing content which i have actually experienced. With luck , I can get more info out of your priceless knowledge. Appreciate it

This is generally a wonderful website i should say,I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and really amazing and impressive website design.

excellent blog, I think the report that you simply produce is a good idea to any or all who seem to see clearly. I have to watch for your site another time.

Wonderful and also superb sunset viewed out of regarding any mountain that has a ditch inside. Many thanks for sharing the helpful theme.

Thank you for the good writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you!

Very nice and informative post. Keep up the good work. Please remember that i m waiting for your next awesome post...

Very good python skills you have. Lot to learn from your blog!

Nice effort, very informative, this will help me to complete my task

I suggest this site to my friends so it could be useful & informative for them also. Great effort.

I've been trying to find good info about it virtually three hrs. An individual taught me to be a lot without a doubt and reading this article your own write-up I've discovered many brand-new and useful information about this specific issue.

Post your comment:

Author:

  • chaiwat

Archives:

Powered by Django.