【问题标题】:Using an embedded Iframe in Django?在 Django 中使用嵌入式 iframe?
【发布时间】:2017-10-07 01:16:34
【问题描述】:

如何在 Django 中使用 iframe。目前它在我自己的文件中搜索 src url。我如何告诉它不要查看我的文件而是查看 url?

目前我将嵌入代码减去标签存储在数据库中,然后尝试在我的模板中动态生成它。

games.embed = 'allowtransparency="true" width="485" height="402" src="//scratch.mit.edu/projects/embed/82384372/?autostart=false" frameborder="0" allowfullscreen'

{% extends 'code_games/base.html' %}

{% block content %}
  <div class="game">

      {{games.title|linebreaks}}
      <iframe '{{ games.embed }}'></iframe>

  </div>
{% endblock %}

iframe 本身会显示在我的页面上,但它的内容不会。

每个错误的请求 URL:

Request URL:    http://chacemcguyer.pythonanywhere.com/games/1/%22/scratch.mit.edu/projects/embed/82384372/?autostart=false%22

您可以看到它在我的网站中搜索 url。我该如何解决?

错误还说:

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

然后它会显示我所有来自 settings.py 的 url

【问题讨论】:

    标签: django python-3.x iframe django-models django-templates


    【解决方案1】:

    我找到了解决办法!

    我要做的是确保来自我的数据库的 iframe 内容是 |safe

    我变了:

    <iframe src='{{ games.embed }}'></iframe>
    

    <iframe src='{{ games.embed|safe }}'></iframe>
    

    【讨论】:

      猜你喜欢
      • 2011-09-10
      • 2013-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-11
      • 2022-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多