开发者

How to alter the URI in django?

开发者 https://www.devze.com 2023-03-05 18:28 出处:网络
http://packages.python.org/django_simple_feedback/ref/request-response.html tells that the absolute URI is built using the server variables available in this request. So, How can I alter the URI using

http://packages.python.org/django_simple_feedback/ref/request-response.html tells that the absolute URI is built using the server variables available in this request. So, How can I alter the URI using HttpRequest.build_absolute_uri.

My situation is: /foo/bar/2/ is the url having corresponding view load_view(request)开发者_运维知识库 Before rendering the template I want to alter the URI by attaching the new absolute URI in the request. So, that My templte renders on the URL /foo/.


You can use django.shortcuts.redirect to redirect to a different location:

def load_view(request):
    return redirect('/foo/')

You will still need a corresponding view setup for that url, of course, as this will cause the user's browser to redirect to /foo/. If you want to change the url without refreshing the page, you can do this with HTML5 now:

window.history.pushState('','foo','/foo/');
0

精彩评论

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

关注公众号