user1328021
user1328021

Reputation: 9840

What is the proper way to pass *args and **kwargs to a view?

Getting the error Don't mix *args and **kwargs in call to reverse()! when trying to pass args and kwargs to a view. I have tried many things at this point and can't get my head around this -- completely stuck on how to pass both to a view.

I need to pass both unipart and newfile to another view.

url(r'^(\d+)/(\d+)/convert/$', 'store.views.changetool', name = "convert"),
url(r'^(\d+)/view_part/$','store.views.view_part',name="view_part"),

VIEWS.PY (changetool)

def changetool (request, id, unipart=None):
    part = Part.objects.get(id=id)
    file = str (part.content)
    newfile = FormatConversion.ConvertToNew(file)
    return redirect('view_part', unipart, newfile = newfile)

VIEWS.PY (view_part)

def view_part(request, part_id, newfile = None):

Upvotes: 2

Views: 4331

Answers (1)

Joseph Victor Zammit
Joseph Victor Zammit

Reputation: 15320

You have to have these imports:

from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect

and your return statement should be:

return HttpResponseRedirect(
    reverse('path.to.function.view_part', args=(unipart, newfile))
)

Relevant docs here.

Upvotes: 3

Related Questions