Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8310127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:20:47+00:00 2026-06-08T19:20:47+00:00

How I would dynamically create a few form fields with different questions, but the

  • 0

How I would dynamically create a few form fields with different questions, but the same answers?

from wtforms import Form, RadioField
from wtforms.validators import Required

class VariableForm(Form):

    def __init__(formdata=None, obj=None, prefix='', **kwargs):
        super(VariableForm, self).__init__(formdata, obj, prefix, **kwargs)
        questions = kwargs['questions']
        // How to to dynamically create three questions formatted as below?

    question = RadioField(
            # question ?,
            [Required()],
            choices = [('yes', 'Yes'), ('no', 'No')],
            )

questions = ("Do you like peas?", "Do you like tea?", "Are you nice?")  
form = VariableForm(questions = questions)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:20:50+00:00Added an answer on June 8, 2026 at 7:20 pm

    It was in the docs all along.

    def my_view():
        class F(MyBaseForm):
            pass
    
        F.username = TextField('username')
        for name in iterate_some_model_dynamically():
            setattr(F, name, TextField(name.title()))
    
        form = F(request.POST, ...)
        # do view stuff
    

    What I didn’t realize is that the class attributes must be set before any instantiation occurs. The clarity comes from this bitbucket comment:

    This is not a bug, it is by design. There are a lot of problems with
    adding fields to instantiated forms – For example, data comes in
    through the Form constructor.

    If you reread the thread you link, you’ll notice you need to derive the class, add fields to that, and then instantiate the new class. Typically you’ll do this inside your view handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create a few panel dynamically in my window form application.
I'm trying to create a function that would dynamically allocate an array, sets the
I would like to dynamically allocate memory from the machine_init function in my arm
I've asked a few questions which have touched around this issue, but I've been
I have a template linkedList that I would like to dynamically create head pointers
I have a situation where I would like to dynamically create an object through
I would like to dynamically create a minimal transparent bar graph to display over
I am learning ASP.Net. I have a dynamically created ImageButton that I would like
I created Extjs.Panel and now I would like to dynamically load a content to
i would like you to help me. I want to create dynamicly table (screenshot).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.