python - Django add an attribute class form in __init__.py -


my form class

from django import forms  class form(forms.form):     your_name = forms.charfield(label='your name ', max_length=100) 

my app file __init__.py

from django import forms my_app.forms import form captcha.fields import recaptchafield  def register(form):  form.captcha=captchafield()  register(form) 

code in __init__.py add attribute captcha not on page.

i tried so

my form class

from django import forms  class form(forms.form):     your_name = forms.charfield(label='your name ', max_length=100)     captcha=captchafield() 

it works, have different! want add сaptcha many forms. want add captcha without changing form classes. want change form classes during initialization. how it???

you need assign field form.fields, not form.

however not way this. instead, should make forms inherit shared parent class, defines captcha field.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -