Django 在iframe里跳转顶层url的例子
时间:2021-05-22 08:40:06|栏目:Python代码|点击: 次
描述
A网页为一个专门设计的登录页面login.html,通过iframe嵌套在B页面中index.html,登录后会进入后台C页面consule.html.问题来了,登录成功后,通过Django-url跳转,页面一直在iframe里面,没有跳出嵌入的框架中。
解决方法
通过HttpResponse来返回一段js脚本,直接让你丫的跳,代码如下
def login(request):
login_form = loginForm()
if request.method == 'POST':
login_form = loginForm(request.POST)
if login_form.is_valid():
username = login_form.data['username']
#通过js来跳转页面,取巧
jump_to_console = '''<html><body onLoad="window.top.location.href='./index_console'" ></body></html>'''
response = HttpResponse(jump_to_consule)
response.set_cookie("username",username")
return response
else:
pass
return render_to_response('login_iframe.html', {'form': login_form},)
上一篇:python实现给scatter设置颜色渐变条colorbar的方法
栏 目:Python代码
下一篇:Pycharm保存不能自动同步到远程服务器的解决方法
本文标题:Django 在iframe里跳转顶层url的例子
本文地址:http://www.codeinn.net/misctech/126349.html






