It seems to like that! `(arg1, OTHER_VAL=OTHER_VAL)
Now I'm trying to access that other_value:
def __init__(self, *args, **kwargs):
OTHER_VAL = kwargs.get('OTHER_VAL') #tried these: #kwargs['OTHER_VAL']
#kwargs.pop('OTHER_VAL')
super(MY_FORM, self).__init__(*args, **kwargs)
Keep on getting errors like:
`KeyError: 'OTHER_VAL'`
# or
__init__() got an unexpected keyword argument 'OTHER_VAL'
On Saturday, June 23, 2018 at 9:56:15 AM UTC-4, Tomasz Knapik wrote:
>
> You get that error because you use kwargs.pop (presumably that's why) and
> you pass OTHER_VALUE as a positional argument.
>
> E.g.
>
> MY_FORM(request.POST, OTHER_VALUE=OTHER_VALUE)
>
>
> would pass it as a keyword argument and then you can
> use kwargs.pop('OTHER_VALUE') in the form's init.
>
> On Fri, 2018-06-22 at 18:37 -0700, 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 [email protected] <javascript:>.
> To post to this group, send email to [email protected]
> <javascript:>.
> 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/61a17825-0a19-4573-8893-49e1b715d045%40googlegroups.com
>
> <https://groups.google.com/d/msgid/django-users/61a17825-0a19-4573-8893-49e1b715d045%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
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/cec9f435-b36b-46df-a384-e0f81d4deb33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.