开发者

Django -- pass "next" parameter to cancel button?

开发者 https://www.devze.com 2023-04-12 13:41 出处:网络
I know how to pass a next get parameter to a view so that when the view redirects, it goes to whatever url is in next. Is it possible to do this with the cancel button of a form?

I know how to pass a next get parameter to a view so that when the view redirects, it goes to whatever url is in next. Is it possible to do this with the cancel button of a form?

If my form buttons are like this:

 开发者_如何学C <input type="submit" value="Save Changes"><input type="button" value="Cancel Changes" onclick="window.location.href='/systems/'">

Is there some way to add the next parameter into the href instead of /systems/?

Thanks!


Well, this is just HTML in your template, so why can't you do

onclick="window.location.href='{{ myurl }}'">

?

Edit after comment

Sounds like you need a context processor, which automatically adds the value of the next GET parameter to the context. As simple as:

def get_next(request):
    if 'next' in request.GET:
        return {'next': request.GET['next']}

Now add this to the list of CONTEXT_PROCESSORS in settings.py, and make sure you use a RequestContext when rendering your template (or just the new render() shortcut).

0

精彩评论

暂无评论...
验证码 换一张
取 消