将* args和** kwargs传递给视图的正确方法是什么?

时间:2013-07-03 18:49:36

标签: django

尝试将args和kwargs传递给视图时获取错误Don't mix *args and **kwargs in call to reverse()!。我已经尝试了很多东西,并且无法理解这一点 - 完全坚持如何将两者都传递给视图。

我需要将unipartnewfile传递给另一个视图。

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):

1 个答案:

答案 0 :(得分:3)

您必须拥有这些导入:

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

并且您的return声明应为:

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

相关文档here