假设我有
def bar(request):
template = loader.get_template('activation/bar_chart.html')
context = RequestContext(request,{'name':'bar_chart'})
return HttpResponse(template.render(context))
我想通过模板中的javascript发送http get请求
$.get('/bar/')
但是它没有渲染bar_chart.html,我仍然停留在当前的html页面。
如果我在jquery中使用load函数
$('body').load('/bar/')
然后 bar_chart.html 的内容将替换当前 html 页面的正文。但我想转到一个新页面(即url应该是/bar)
如何使用 django 和 jquery 做到这一点?
谢谢
最佳答案
如果您想转到 /bar/
页面,只需更改 location
属性即可。这里不需要 JQuery:
location.href = "/bar/";
关于javascript - 通过 javascript 渲染 django View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29257039/