django - Captured URL parameters in form -



django - Captured URL parameters in form -

i using userena , trying capture url parameters , them form i'm lost how this.

what in template is:

<a href="/accounts/signup/freeplan">free plan</a><br/> <a href="/accounts/signup/proplan">pro plan</a><br/> <a href="/accounts/signup/enterpriseplan">enterprise plan</a><br/>

and in urls.py

url(r'^accounts/signup/(?p<planslug>.*)/$','userena.views.signup',{'signup_form':signupformextra}),

then, ideally, i'd utilize planslug in forms.py set user plan in profile.

i'm lost how captured url parameter custom form. can utilize extra_context, have override userena signup view?

if utilize class based views, can overwrite def get_form_kwargs() method of formmixin class. here can pass parameters need form class.

in urls.py:

url(r'^create/something/(?p<foo>.*)/$', mycreateview.as_view(), name='my_create_view'),

in views.py:

class mycreateview(createview): form_class = myform model = mymodel def get_form_kwargs(self): kwargs = super( mycreateview, self).get_form_kwargs() # update kwargs form init method yours kwargs.update(self.kwargs) # self.kwargs contains url conf params homecoming kwargs

in forms.py:

class myform(forms.modelform): def __init__(self, foo=none, *args, **kwargs) # explicit define foo keyword argument, cause otherwise kwargs # contain , passes on super class, fails cause it's not # aware of foo keyword argument. super(myform, self).__init__(*args, **kwargs) print foo # prints value of foo url conf param

hope helps :-)

django django-users

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

How do you set up a perforce server to work over the internet? -

ios - Lagging ScrollView with UIWebview inside -