Looks like I was missing an `initial` inside init... 0_o

https://stackoverflow.com/questions/1993014/passing-kwargs-to-django-form



On Friday, June 22, 2018 at 9:37:26 PM UTC-4, HashRocketSyntax wrote:
>
> When I call my form in my view, I am trying to pass MY_VALUE to the form 
> as an argument.
>
> I am doing this because I want to get my validation out of my views and 
> into my forms.
>
> *views.py*
> OTHER_VALUE = "the query that i run"
> if request.method=='POST':
>   form = MY_FORM(request.POST, OTHER_VALUE)
>
> *forms.py*
> class MY_FORM(forms.Form):
>
>   real_value = forms.CharField()
>   def clean_real_value(self):
>     if OTHER_VALUE ...
>
>
> *This throws the error:*
> __init__() got an unexpected keyword argument 'OTHER_VALUE'
>
>
> =========
>
> I've tried setting the init with kwargs
> class MY_FORM(forms.Form):
>   real_value = forms.CharField()
>
>   def __init__(self, *args, **kwargs): 
>     OTHER_VALUE = kwargs.pop('OTHER_VALUE') 
>     super(MY_FORM, self).__init__(*args, **kwargs)
>
>
> error:
> Exception Value: 'employee'
> Exception Location: /Users/macbook/Desktop/OrgDB/orgchart/forms.py in 
> __init__, line 42
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/43fa9a79-892a-451d-86e1-c945eb53c85e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to