django - 在 Django 管理视图中显示 iframe 元素
问题描述
我一直在尝试向 Django 的管理站点添加一个简单的视图,就像这样
# collection_management/admin.py
class MyAdminSite(admin.AdminSite):
...
def plasmid_map_view(self, request):
return render(request, 'admin/collection_management/plasmid_map.html')
...
它使用一个模板,其中包含一个加载外部 url 的 iframe 元素
# templates/admin/collection_management/plasmid_map.html
...
{% block content %}<div id="content-main">
<iframe
style="height: 80vh; width: 100%; resize: both; overflow: auto; border:None;"
src="https://designer.genomecompiler.com/plasmid_iframe?file_url=http://s3.amazonaws.com/gcc_production/plasmid_viewer/OG34_OG34_pSF-OXB19.gb">
</iframe>
</div>
{% endblock %}
...
当我尝试加载页面时,我得到一个奇怪的行为,即 Django 将我的网站(example.net:8443)的“根”url 附加到应该在 iframe 内打开的地址,这显然不存在
https://example.net:8443/collection_management/plasmid_map/%E2%80%8Bhttps:/designer.genomecompiler.com/plasmid_iframe?file_url=http://s3.amazonaws.com/gcc_production/plasmid_viewer/OG34_OG34_pSF-OXB19.gb%E2%80%8B
我怎样才能阻止 Django 这样做?
解决方案
src 字符串两侧有一些隐藏字符
推荐阅读
- python - 如何让自定义模块引用主 Python 上的导入模块
- html - 错误:[$injector:unpr] 未知提供者:treeGridProvider(Angular Grid Tree 表不工作)
- android - Android:TextToSpeech Invalid int:“OS”异常
- oracle - 从 PLSQL 字符串替换多个 CHR()
- amazon-web-services - 将 Pdf 文件从本地文件夹传输到 AWS
- javascript - 错误:操作必须是普通对象。在删除按钮中使用自定义中间件进行异步操作?
- asp.net-core - 在 Asp.net Core 2.1 中使用 IActionFilter 进行 FluentValidation
- angular - 角度路由器:水平显示子级(作为兄弟姐妹)
- sql - 面向页面的嵌套循环连接 - 查询优化
- sql-server - 从 SSAS 数据源视图查看未显示在多维数据集分区下