【问题标题】:Create a hyperlink to external website in django在 django 中创建指向外部网站的超链接
【发布时间】:2021-07-21 20:35:04
【问题描述】:

关于在 django 中创建指向外部网站的超链接,例如在 google.com 中,我有一个小问题 我的 html 文件中有类似的内容:

Adres www: <a href="{{ det_wpisu.adres_www }}">{{ det_wpisu.adres_www }}</a> <br />

但是当我点击显示我时的 www 地址:

http://localhost:8000/detale/3/www.google.com

并返回 404 页面。

【问题讨论】:

  • 你的 html 中的值是什么?如果您没有在链接前添加http:// 可能是正常的

标签: django django-templates href


【解决方案1】:

确保变量det_wpisu.adres_www 包含一个完整网址,其中包括https://,例如:

context = {'det_wpisu.adres_www': 'https://www.google.com'}

【讨论】:

    【解决方案2】:

    考虑使用 http 的嵌入解决方案。所以它会是这样的:

    <a href="http://www.google.com">Text</a>
    

    【讨论】:

      【解决方案3】:

      在 Django 模板中添加 http:// 字符串很容易。不要修改视图和/或数据库,试试这个...

      <a href="http://{{ det_wpisu.adres_www }}">{{ det_wpisu.adres_www }}</a> 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-22
        • 1970-01-01
        • 1970-01-01
        • 2016-07-05
        • 1970-01-01
        • 2016-08-15
        • 1970-01-01
        • 2010-09-18
        相关资源
        最近更新 更多