【问题标题】:how to avoid referer checking in django?如何避免在 django 中检查引用者?
【发布时间】:2013-07-05 09:14:54
【问题描述】:

我必须使用 django 来创建网页。

在 html 中,我将外部图像链接分配给 img src 标签。

但是,403 禁止错误并且不显示图像。

当我将图像外部链接粘贴到浏览器地址时,图像显示。

我认为.. 这是推荐人检查。所以我在Changing the http referer in javascript 中使用了 ReferrerKiller.js。

显示第一张图片。但其他不是。

我使用 chrome 开发者工具检查网络。

其他图片已取消。我不知道。

我想听听有关此问题的任何想法。.Referer 检查以及为什么只显示第一张图片?其他没有?

在 home.html 下方

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
{% load staticfiles %}

<html> 
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" src="{% static "js/ReferrerKiller.js" %}"></script>
<title>island</title> 
</head>
<body> 
<h1> nanpa </h1> 
<br/>

{% for entrySummary in entrySummaryList %} 
    title : 
    <a href="{{entrySummary.entry_link}}">{{ entrySummary.entry_title }}</a>
    {{ entrySummary.entry_pub_date }} <br/>

    description : {{ entrySummary.entry_description }} <br/>
    image : <span id="image_kill_referrer"></span> 
    <!-- <img src= ("{{ entrySummary.entry_representaion_img }}"/> -->
    <script>
    document.getElementById('image_kill_referrer').innerHTML = ReferrerKiller.imageHtml("{{
    entrySummary.entry_representaion_img }}");
    </script>   
{% endfor %}   
</body> 
</html>

【问题讨论】:

    标签: django image http referer


    【解决方案1】:

    document.getElementById() 只返回一个项目(第一个项目,因为您代码中的所有图像都具有相同的 id)。使用其他方法,例如document.getElementsByClassName

    试试下面的代码:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    {% load staticfiles %}
    
    <html>
        <head>
            <meta charset="utf-8" />
            <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
            <script type="text/javascript" src="{% static "js/ReferrerKiller.js" %}"></script>
            <title>island</title> 
        </head>
    
        <body> 
            <h1> nanpa </h1>
            <br/>
    
        {% for entrySummary in entrySummaryList %} 
            title :
            <a href="{{entrySummary.entry_link}}">{{ entrySummary.entry_title }}</a>
            {{ entrySummary.entry_pub_date }} <br/>
    
            description : {{ entrySummary.entry_description }} <br/>
            image : <span class="image_kill_referrer"></span>
        {% endfor %} 
            <script>
            var i, images = document.getElementsByClassName('image_kill_referrer');
            var urls = [
        {% for entrySummary in entrySummaryList %} 
                "{{ entrySummary.entry_representaion_img }}",
        {% endfor %}
                "DUMMY"
            ];
            for (i = 0; i < images.length; i++) {
                images[i].innerHTML = ReferrerKiller.imageHtml(urls[i]);
            }
            </script>
        </body>
    </html>
    

    或者,为每张图片使用不同的 id:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    {% load staticfiles %}
    <html> 
        <head>
            <meta charset="utf-8" />
            <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
            <script type="text/javascript" src="{% static "js/ReferrerKiller.js" %}"></script>
            <title>island</title> 
        </head>
        <body> 
            <h1> nanpa </h1> 
            <br/>
    
        {% for entrySummary in entrySummaryList %} 
            title : 
            <a href="{{entrySummary.entry_link}}">{{ entrySummary.entry_title }}</a>
            {{ entrySummary.entry_pub_date }} <br/>
    
            description : {{ entrySummary.entry_description }} <br/>
            image : <span id="image_kill_referrer{{ forloop.counter }}"></span> 
            <script>
            document.getElementById('image_kill_referrer{{ forloop.counter }}').innerHTML = ReferrerKiller.imageHtml("{{
            entrySummary.entry_representaion_img }}");
            </script>   
        {% endfor %}   
        </body> 
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-11
      • 2016-12-01
      相关资源
      最近更新 更多