Django解决frame拒绝问题的方法

2022-07-26,,,,

一、home页使用frame

template/home.html

<!doctype html>
<html lang="en">
<meta http-equiv="content-type" content="text/html" charset="utf-8">
<head>
  <title>自动化测试平台</title>
</head>

<frameset id="frame" rows="*" cols="265,*" framespacing="0" frameborder="yes" border="0">
  <frame src="../left" name="leftframe" scrolling="auto" noresize>
  <frame src="../welcome" name="mainframe" scrolling="no" noresize>
</frameset>
<noframes>
  <body>
  <h1>hello</h1>
  </body>
</noframes>
</html>

二、视图文件

autotestplat/views.py

def home(request):
  return render(request, 'home.html')

def left(request):
  return render(request, 'left.html')

def welcome(request):
  return render(request, 'welcome.html')

三、urls映射文件

urlpatterns = [
  path('admin/', admin.site.urls),
  path('', views.login),
  path('login/', views.login),
  path('home/', views.home),
  path('left/', views.left),
  path('welcome/', views.welcome),
]

命令行执行python manage.py runserver后,chrome浏览器打开http://127.0.0.1:8000/home/,显示如下图。打开f12,报以下错误。

四、解决方案

在setting.py中设置:

# 解决frame跨域问题
x_frame_options = 'allowall url'

到此这篇关于django解决frame拒绝问题的方法的文章就介绍到这了,更多相关django frame拒绝内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

《Django解决frame拒绝问题的方法.doc》

下载本文的Word格式文档,以方便收藏与打印。