带有附加query_string的Django HttpResponseRedirect

时间:2014-02-04 06:52:38

标签: python django

我遇到这种情况我的注册页面在成功注册后就像http://localhost:8000/signUp?qid=ca1480f4这样的网址提供了我想用这个查询将用户重定向到登录页面?qid=ca1480f4

views.py

class SignUp(FormView):
success_url = '/login'


def post(self, request, *args, **kwargs):
    form = self.form_class(request.POST)
    if form.is_valid():
        form.save()
        return HttpResponseRedirect(self.get_success_url())
    else:
        return self.form_invalid(form)

我需要进行哪些更改才能使用self.request.META['QUERY_STRING']

获取该查询

1 个答案:

答案 0 :(得分:3)

替换以下行:

return HttpResponseRedirect(self.get_success_url())

with(追加查询字符串):

return HttpResponseRedirect(self.get_success_url() + '?' + request.META['QUERY_STRING'])