Django redirect using reverse() to a URL that relies on query strings

前端 未结 4 1896
Happy的楠姐
Happy的楠姐 2021-01-04 07:05

I\'m writing a django application with a URL like \'http://localhost/entity/id/?overlay=other_id\'. Where id is the primary key of the particular entity and overlay is an o

4条回答
  •  耶瑟儿~
    2021-01-04 07:42

    Can't you just check for an overlay_id and add it to your url?

    redirect_url = reverse( ... )
    extra_params = '?overlay=%s' % overlay_id if overlay_id else ''
    full_redirect_url = '%s%s' % (redirect_url, extra_params)
    return HttpResponseRedirect( full_redirect_url )
    

提交回复
热议问题