小编Pra*_*een的帖子

将Base64字符串加载到Python图像库中

我通过ajax将图像作为base64字符串发送到django.在我的django视图中,我需要调整图像大小并将其保存在文件系统中.

这是一个base64字符串(简化):

data:image/jpeg;base64,/9j/4AAQSkZJRg-it-keeps-going-for-few-more-lines=
Run Code Online (Sandbox Code Playgroud)

我尝试使用下面的python代码在PIL中打开它:

img = cStringIO.StringIO(request.POST['file'].decode('base64'))
image = Image.open(img)
return HttpResponse(image, content_type='image/jpeg')
Run Code Online (Sandbox Code Playgroud)

我正在尝试显示上传的图像,但是firefox抱怨说 'The image cannot be displayed because it contains error'

我无法弄清楚我的错误.

解:

pic = cStringIO.StringIO()

image_string = cStringIO.StringIO(base64.b64decode(request.POST['file']))

image = Image.open(image_string)

image.save(pic, image.format, quality = 100)

pic.seek(0)

return HttpResponse(pic, content_type='image/jpeg')
Run Code Online (Sandbox Code Playgroud)

python django base64 image python-imaging-library

10
推荐指数
1
解决办法
9973
查看次数

是否可以在地址栏中使用注入$ .post()?

我有一个javascript,其中我使用$ .post()命令将变量发布到php文件,我在相同的.js文件中硬编码的php文件的URL.

我只是想知道是否有人从地址栏中注入$ .post()命令并将无效数据发送到PHP文件?

如果是,如何防止或如何检测这些无效数据?

javascript address-bar post code-injection

0
推荐指数
1
解决办法
926
查看次数

如何将提交事件添加到动态生成的表单?

以下是生成表单的PHP代码:form.php

 <?php
    echo '
    <form action="/wall/comment.php" method="post" id="submit-comment-form" name="'.$postid.'"> 
    <div class="write-comment-profile-pic">
    <img src= "'.$myprofilepic.'" width="30" height="30""/>
    </div>
    <div class="write-comment-textbox-wrap">
    <input type="text" class="textbox4" id="write-comment-textbox" value="Write a comment..." name="comment" style="width:65%;" />
    </div>
   </form>
   ';
   ?>
Run Code Online (Sandbox Code Playgroud)

得到form.php的Jquery代码

$('#images img').click(function() { 
$.get('form.php', function(data) {
$('#image-pop-up').html(data);
});
});
Run Code Online (Sandbox Code Playgroud)

这里是需要提交表单的jquery代码:

$('#image-pop-up').on('submit', '#submit-comment-form', function() { 
evt.preventDefault();       
});
Run Code Online (Sandbox Code Playgroud)

在index.html中,image-pop-up div只是一个空的

<div id="image-pop-up">

</div>
Run Code Online (Sandbox Code Playgroud)

这不起作用......出了什么问题?怎么解决?

jquery

0
推荐指数
1
解决办法
3926
查看次数

使用jquery在DOM中更改锚类

<a class="behaviour1" href="link1">Test</a>
Run Code Online (Sandbox Code Playgroud)

我有两个针对'behaviour1'和'behaviour2'类的点击事件.

$('.behaviour1').click(function() {
    alert('behaviour - 1');
    $(this).prop('class', 'behaviour2');
});

$('.behaviour2').click(function() {
    alert('behaviour - 2');
    $(this).prop('class', 'behaviour1');
});
Run Code Online (Sandbox Code Playgroud)

我想改变锚标签的行为.但它不起作用.我每次都得到'behaviour1'.它没有变成'behavour2'.

我如何让它工作?

javascript jquery dom

0
推荐指数
1
解决办法
79
查看次数