Jquery django-任何使用Ajax的图像上传和显示方法?

Jquery django-任何使用Ajax的图像上传和显示方法?,jquery,ajax,django,django-forms,django-imagekit,Jquery,Ajax,Django,Django Forms,Django Imagekit,在django应用程序中,我使用ImageKit调整加载到服务器的图像的大小 models.py forms.py template.html 使用某种Ajax方法,如何消除template.html中的submit按钮,以便当用户从其机器中选择图像时,图像自动上载到服务器,然后显示回服务器 我感谢你的帮助 我可能会使用: 使用ajax提交表单,然后使用成功回调将图像加载到dom中。谢谢您的链接!我会调查的。有真实的例子吗? class Pictures(ImageModel): use

在django应用程序中,我使用ImageKit调整加载到服务器的图像的大小

models.py

forms.py

template.html

使用某种Ajax方法,如何消除template.html中的submit按钮,以便当用户从其机器中选择图像时,图像自动上载到服务器,然后显示回服务器

我感谢你的帮助

我可能会使用:


使用ajax提交表单,然后使用成功回调将图像加载到dom中。

谢谢您的链接!我会调查的。有真实的例子吗?
class Pictures(ImageModel):
    user = models.ForeignKey(User)
    original_image = models.ImageField(upload_to='userpx')

    class IKOptions:
        # This inner class is where we define the ImageKit options for the model
        spec_module = 'userprofile.specs'
        cache_dir = 'modpics'
        image_field = 'original_image'
        save_count_as = 'num_views'
    def __unicode__(self):
        return u'%s' % (self.original_image)
class PicturesForm(forms.Form): 
   image = forms.ImageField()
<img src="{{ p.thumbnail_image.url }}" >

<form action="" method="POST" class="cmxform" enctype="multipart/form-data">
{% csrf_token %}
{{aform.as_p}}
<input type="submit" value="submit" name="picture_button" />        
</form>
   if 'picture_button' in request.POST:
        aform = PicturesForm(request.POST, request.FILES)
        if aform.is_valid():
            # an UploadedFile object
            a_user = User.objects.get(id=request.user.id)

            #Check if image entry exists 
            try:
                p = Pictures.objects.get(user=request.user.id)

            except Pictures.DoesNotExist: 
                picture = Pictures.objects.create(user = a_user)
                image_file = request.FILES['image']
                picture.original_image.save(image_file.name, image_file)

                #show picture and form
                p = Pictures.objects.get(user=request.user.id)
                aform = PicturesForm()

            else:
                p.delete()
                picture = Pictures.objects.create(user = a_user)
                image_file = request.FILES['image']
                picture.original_image.save(image_file.name, image_file)

                #show image and form
                p = Pictures.objects.get(user=request.user.id)
                aform = PicturesForm()


    else:
        p = Pictures.objects.get(user=request.user.id)
        aform = PicturesForm()