Django应用程序中的JQuery脚本 - 403错误 [英] JQuery script in Django app - 403 error

查看:96
本文介绍了Django应用程序中的JQuery脚本 - 403错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Heroku本地运行一个Django应用程序,s3是我的媒体+静态文件。该应用程序包括一个迷你幻灯片,通过命令循环播放图像,并且不再拖动图像,我在幻灯片中循环浏览时出现403错误。


  1. 脚本嵌入到我的HTML中,而不是单独的文件。这是
    ,因为我知道如何使用{{
    listing.image1.url}}

  2. 当我点击下一个按钮时,我可以看到它通过图像循环浏览
    (虽然它在我的浏览器中显示一个破碎的图像)

  3. s3设置似乎好 - 所有其他媒体和静态文件都是

  4. 正常显示脚本在我移动到S3之前工作正常

  5. 我可以单独访问图像我的HTML

这是我的脚本,这是我第一次写jquery,所以写得不好,左滚动有点时髦:

 < script type =text / javascriptsrc =http://code.jquery.com/jquery- 1.8.0.min.js>< /脚本> 
< script type =text / javascript>

$(document).ready(function(){
var imageName = [{{listing.image1.url}},{{listing.image2.url}} ,{{listing.image3.url}}];
var indexNum = 1;

$(#right-scroll)点击(function(){
$(#picture)。fadeOut(30,function(){
$(#picture)。attr(src,imageName [indexNum]);
indexNum ++;
if(indexNum> 2){indexNum = 0;}
$(#picture)fadeIn(50);

$(#left-scroll (function(){
$(#picture)。fadeOut(30,function(){
$(#picture)。attr(src,imageName [indexNum]);
indexNum--;
if(indexNum< 0){indexNum = 2;}
$(#picture)fadeIn(50);

} );
});
});
});
});
< / script>

以下是相关的HTML部分:

 < div id =image-gallery> 
< img id =picturesrc ={{listing.image1.url}}>
< img class =scrollid =left-scrollsrc ={%static'left-scroll.jpg'%}>
< img class =scrollid =right-scrollsrc ={%static'right-scroll.jpg'%}>
< / div>


解决方案

将以下内容添加到您的设置文件中:

  AWS_QUERYSTRING_AUTH = False 

这将停止生成的Expires查询参数。






AWS S3使用django statics动态变化的URL URL


I'm running a Django app locally using Heroku, and s3 for my media + static files. The app includes a mini slide show that cycles through images on command, and is no longer pulling in images, I'm seeing a 403 error as I cycle through the slideshow.

  1. The script is embedded in my HTML, not a separate file. This is because the I know how to to call the images using "{{ listing.image1.url }}"
  2. When I click the next button, I can see it cycling through images (although it's showing a broken image in my browser)
  3. The s3 setup seems fine - all other media and static files are
  4. surfacing properly The script was working fine before I moved to S3
  5. I can access the images individually from my HTML

Here is my script, it's my first time writing jquery so it's not well written and the left-scroll is a bit funky:

<script type = "text/javascript" src = "http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script type = "text/javascript">

$(document).ready(function() {
    var imageName = ["{{ listing.image1.url }}", "{{ listing.image2.url }}", "{{ listing.image3.url }}"];
    var indexNum = 1;

    $("#right-scroll").click(function() {
        $("#picture").fadeOut(30, function() {
            $("#picture").attr("src", imageName[indexNum]);
            indexNum++;
            if (indexNum > 2) {indexNum = 0;}
            $("#picture").fadeIn(50);

    $("#left-scroll").click(function() {
        $("#picture").fadeOut(30, function() {
            $("#picture").attr("src", imageName[indexNum]);
            indexNum--;
            if (indexNum < 0) {indexNum = 2;}
            $("#picture").fadeIn(50);

        });
        });             
        });
    });
});
</script>

Here is the relevant HTML section:

<div id = "image-gallery">
            <img id = "picture" src ="{{ listing.image1.url }}">
            <img class = "scroll" id = "left-scroll" src="{% static 'left-scroll.jpg' %}">
            <img class = "scroll" id = "right-scroll" src="{% static 'right-scroll.jpg' %}">
</div>

解决方案

Add the following to your settings file:

AWS_QUERYSTRING_AUTH = False

This will stop the Expires query parameter being generated.


AWS S3 Url changing dynamically with django statics

这篇关于Django应用程序中的JQuery脚本 - 403错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆