Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass kwargs in URL in django

Tags:

python

django

In the django doc the url function is like this

url(regex, view, kwargs=None, name=None, prefix='')

I have this

url(r'^download/template/(?P<object_id>\d+)/$', views.myview().myfunction,model=models.userModel, name="sample")

This is my view

class myview(TemplateView):

    def myfunction(self,request, object_id, **kwargs):
        model = kwargs['model']

I get this error

url() got an unexpected keyword argument 'model'
like image 913
Mirage Avatar asked Dec 03 '12 07:12

Mirage


1 Answers

You are trying to pass in a model keyword argument to the url() function; you need to pass in a kwargs argument instead (it takes a dictionary):

url(r'^download/template/(?P<object_id>\d+)/$', views.myview().myfunction, 
    kwargs=dict(model=models.userModel), name="sample")
like image 84
Martijn Pieters Avatar answered Sep 28 '22 00:09

Martijn Pieters