I would like to pass kwargs to my view function through URL.
urls.py
urlpatterns = [
# ------------- set relations --------------------
url(r'^approve-form/$', views.approve_form,
{'content_type':None, 'form_id':None,}, name='approve-form'),]
views.py
def approve_form(request, content_type=None, form_id=None):
return HttpResponse('Working')
Now I am using reverse_lazy
function to call the url from on of the model instance
models.py
class FormStatus(models.Model):
content_type = models.ForeignKey(ContentType)
form_id = models.IntegerField(verbose_name='Form Ref ID')
def __str__(self):
return "{}".format(self.content_type)
def get_approve_link(self):
return reverse_lazy("flow-control:approve-form", kwargs={'form_id':self.form_id,
'content_type':self.content_type})'
ERROR
Reverse for 'approve-form' with arguments '()' and keyword arguments '{'content_type': <ContentType: admin sanc model>, 'form_id': 12}' not found. 1 pattern(s) tried: ['flow-control/approve-form/$']
Is something wrong with the approach or is there any better approach for this ?
Thanks in advance.
PS: I tried the url documentation but couldn't figure it out.