jQuery脚本的Django应用程序 - 403错误 [英] JQuery script in Django app - 403 error
问题描述
我运行一个Django应用程序在本地使用的Heroku和S3为我的媒体+静态文件。该应用程序包括一个迷你幻灯片放映周期通过命令图像,图像中不再拉,我看到一个403错误,因为我循环播放幻灯片。
- 的脚本嵌入在我的HTML,而不是一个独立的文件。这是
因为我知道如何使用调用图像
{{ listing.image1.url}}
- 当我点击下一步按钮,我可以看到骑自行车,图像 (尽管它呈现出破碎的形象在我的浏览器)
- 在S3的设置似乎罚款 - 所有其他媒体和静态文件
- 在堆焊正确的脚本工作正常之前,我搬到了S3
- 我可以单独从我的HTML访问图像
下面是我的脚本,这是我第一次写的jQuery所以它不是写得很好,左滚动有点时髦的:
<脚本类型=文/ JavaScript的SRC =HTTP://$c$c.jquery.com/jquery-1.8.0.min.js> < / SCRIPT>
<脚本类型=文/ JavaScript的>
$(文件)。就绪(函数(){
变种imageName = [{{listing.image1.url}},{{listing.image2.url}},{{listing.image3.url}}];
变种indexNum = 1;
$(#右滚动)。点击(函数(){
$(#图片)。淡出(30,函数(){
$(#图片)ATTR(src用户,imageName [indexNum])。
indexNum ++;
如果(indexNum→2){indexNum = 0;}
$(#图象)淡入(50)。
$(左滚动#)。点击(函数(){
$(#图片)。淡出(30,函数(){
$(#图片)ATTR(src用户,imageName [indexNum])。
indexNum--;
如果(indexNum℃,){indexNum = 2;}
$(#图象)淡入(50)。
});
});
});
});
});
< / SCRIPT>
下面是相关的HTML部分:
< DIV ID =图像库>
< IMG ID =图片SRC ={{listing.image1.url}}>
< IMG类=滚动ID =左长卷SRC ={%静态左scroll.jpg%}>
< IMG类=滚动ID =右滚动SRC ={%静态右scroll.jpg%}>
< / DIV>
以下内容添加到您的设置文件:
AWS_QUERYSTRING_AUTH =假
这将阻止过期而生成的查询参数。
<一个href="http://stackoverflow.com/questions/17027343/aws-s3-url-changing-dynamically-with-django-statics/17027684#17027684">AWS S3网址动态变化与Django的静态
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.
- 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 }}"
- When I click the next button, I can see it cycling through images (although it's showing a broken image in my browser)
- The s3 setup seems fine - all other media and static files are
- surfacing properly The script was working fine before I moved to S3
- 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
这篇关于jQuery脚本的Django应用程序 - 403错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!