Python 如何让用户将图像上传到photologue?

Python 如何让用户将图像上传到photologue?,python,photologue,Python,Photologue,我已经设置了Photologue,但我不知道如何让(普通)用户在不使用管理界面的情况下上传图像 我想让用户从HTML5画布上传base64编码的图像,但在第一步,可以从用户的文件系统上传文件 我想我可以修改如何上传文件来使用photologue的照片模型。我假设这意味着以某种方式填充“ImageModel”的ImageField属性“image”。我实际上使用了链接文件上传指南,并将其改编为photologue。从我的canvas元素中,我提取了一个base64数据url,并将表单字段设置为其值

我已经设置了Photologue,但我不知道如何让(普通)用户在不使用管理界面的情况下上传图像

我想让用户从HTML5画布上传base64编码的图像,但在第一步,可以从用户的文件系统上传文件


我想我可以修改如何上传文件来使用photologue的照片模型。我假设这意味着以某种方式填充“ImageModel”的ImageField属性“image”。

我实际上使用了链接文件上传指南,并将其改编为photologue。从我的canvas元素中,我提取了一个base64数据url,并将表单字段设置为其值,然后我可以在Django的服务器端的视图中对其进行解释:

def upload_base64(request):
    # Handle file upload
    if request.method == 'POST':
        form = PhotoCodeForm(request.POST, request.FILES)

        if form.is_valid():
            uploaded_photo_data = base64.b64decode(request.POST['photocode'])

            uploaded_photo_file = ContentFile(uploaded_photo_data)            

            title_str = "Untitled"            
            slug = slugify( title_str + str( datetime.now() ) )

            uploaded_photo = Photo.objects.create( image = default_storage.save(slug, uploaded_photo_file),
                                            title = slug,
                                            title_slug = slug )

            name_upload_gallery = "user-upload-queue"                       

            try:
                upload_gallery = Gallery.objects.get(title_slug__exact=name_upload_gallery)      
            except ObjectDoesNotExist:
                return HttpResponseBadRequest('<html><body><p>The gallery "'+name_upload_gallery+'" does not exist.</p></body></html>')

            upload_gallery.photos.add(uploaded_photo)

            # Redirect to the photo gallery after POST
            return HttpResponseRedirect('/canvas/')
        else:
            return HttpResponseBadRequest('<html><body><p>The entered data was not correct.</p></body></html>')
    else:
        form = PhotoCodeForm() # A empty, unbound form

    return render_to_response(
        'photologue_upload/upload_base64.html',
        {'form': form},
        context_instance=RequestContext(request)
    )
def上传_base64(请求):
#处理文件上传
如果request.method==“POST”:
form=PhotoCodeForm(request.POST、request.FILES)
如果form.is_有效():
上传的照片数据=base64.b64解码(request.POST['photocode'])
上传的照片文件=内容文件(上传的照片数据)
title_str=“无标题”
slug=slugify(title_str+str(datetime.now()))
上传的照片=照片.objects.create(图像=默认的存储.save(slug,上传的照片文件),
title=slug,
标题(段塞=段塞)
name\u upload\u gallery=“用户上传队列”
尝试:
upload\u gallery=gallery.objects.get(title\u slug\uuu exact=name\u upload\u gallery)
除ObjectDoesNotExist外:
返回HttpResponseBadRequest(“库“+name\u upload\u gallery+”不存在。

”) 上传照片库。照片。添加(上传照片) #发布后重定向到照片库 返回HttpResponseRedirect(“/canvas/”) 其他: 返回HttpResponseBadRequest(“输入的数据不正确。

”) 其他: form=PhotoCodeForm()#一个空的、未绑定的表单 返回render\u to\u响应( 'photologue_upload/upload_base64.html', {'form':form}, context\u instance=RequestContext(请求) )

upload_base64.html是一个非常简单的表单,它有一个字段光码,base64字符串粘贴到该字段。

你找到答案了吗?我也有同样的问题。是的,我设法实现了这一点。我几乎修改了链接的答案。我将尝试写一个答案…什么是光码?