我在Django中创建了一个Django,并将其部署在heroku上。我试图显示这个网站从一个html页面使用iframe。然而,当我加载我的html页面时,我得到了错误:gkwhelps.herokuapp.com拒绝了连接。在检查页面时,我得到了以下消息:Refused to display 'http://gkwhelps.herokuapp.com/' in a frame because it set 'X-Frame-Options' to 'deny'.,为了解决这个问题,我修改了gkwhelps.herokuapp.com的settings.py:
MIDDLEWARE = [
...
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
...
from django.http import HttpResponse
from django.views.decorators.clickjacking import xframe_options_exempt
@xframe_options_exempt
def ok_to_load_in_a_frame(request):
return HttpResponse("This page is safe to load in a frame on any site.")我更新了我的网站。但尽管如此,当我重新加载页面时,仍然会遇到相同的错误。我不知道为什么我更新了我的网站。
发布于 2022-07-21 14:48:34
您可以尝试以下方法来设置相同的源文件xframe选项
from django.views.decorators.clickjacking import xframe_options_sameorigin
@xframe_options_sameorigin
def ok_to_load_in_a_frame(request):
return HttpResponse("This page is safe to load in a frame on any site.")如果您想为整个应用程序设置它,可以尝试在您的settings.py文件中添加以下行
X_FRAME_OPTIONS = 'SAMEORIGIN'https://stackoverflow.com/questions/73067429
复制相似问题