Sending argument in reverse_lazy django - Python -
i using reverse_lazy following
def index: if firsttimelogin == 0: response = httpresponseredirect(reverse_lazy('abc', args={'cid': 0})) else: response = httpresponseredirect(reverse_lazy('abc', args={'cid': 1}))
abc view
def abc(request, userid = none, cid =1 ): return httpresponse(cid)
urls.py
url(r'^abc/$', views.abc, name='abc'), url(r'^abc/(?p<userid>.*)/$', views.abc, name='abc'), url(r'^abc/(?p<cid>.*)/$', views.abc, name='abc'),
now when redirected def abc through reverse_lazy url like: baseurl/appname/abc/cid
, here dont know how can fetch value of cid.
please correct if other approach required. need pass argument reverse_lazy want fetch in def abc
update
refering romaan saying: have updated: urls.py as:
url(r'^abc/(?p<cid>.*)/$', views.abc, name='abcfirst')
and redirect as:
response = httpresponseredirect(reverse_lazy('abcfirst', args={'cid': 1}))
still unable access arguments sending through reverse_lazy.
you have 2 urls have same name, , take in same parameters (same regex).
you can't combine these 2 have view take in both, thats not how django works.
you either have to
- make url takes in 2 parameters
- make separate views
but either way, can't use same name different urls.