【发布时间】:2021-07-08 18:19:17
【问题描述】:
我安装了 yangsuite[core],部署它并用 iframe 调用它
<iframe
width="700"
height="800"
src="https://10.225.61.70:7143/netconf/getyang/hangxin+travelsky-set/ietf-interfaces">
</iframe>
这里是视图函数代码 (在目录lib/python3.8/site-packages/ysnetconf/views/rpc.py下):
@login_required
def get_yang(request, yangset=None, modulenames=None):
devices = YSDeviceProfile.list(require_feature="netconf")
replay_dir = get_path('tasks_dir', user=request.user.username)
return render(request, 'ysnetconf/netconf.html', {
'devices': devices,
'yangset': yangset or '',
'modulenames': modulenames or '',
'replay_dir': replay_dir
})
需要登录,我改了代码绕过登录(有一些代码逻辑需要访问request.user)
# @login_required
def get_yang(request, yangset=None, modulenames=None):
devices = YSDeviceProfile.list(require_feature="netconf")
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login
user = authenticate(username='admin', password='password')
login(request, user)
replay_dir = get_path('tasks_dir', user=request.user.username)
return render(request, 'ysnetconf/netconf.html', {
'devices': devices,
'yangset': yangset or '',
'modulenames': modulenames or '',
'replay_dir': replay_dir
})
但是当我打开 ifram 页面时,一个警告提示我应该指定 SameSite。 我找到了一个解决方案,但只在 django 2.2.x 中。这是提到的解决方案:https://stackoverflow.com/a/64338648/7004884
我尝试在 2.0.13 中使用 django-cookies-samesite,但没有成功。
在本文档 (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite#) None) 中,它提到需要设置安全属性,我已经这样做了。我得到的 cookie 是这样的
Set-Cookie: sessionid=2hm53373qoou4kectdy8lv2z4aqp25y8; expires=Mon, 03-May-2021 05:57:13 GMT; HttpOnly; Max-Age=1209600; Path=/; Secure
我认为原因是 django 的版本。 有没有其他方法可以在 django 2.0.13 版本中设置 SameSite 属性?
【问题讨论】: