(Django)如何显示在views.py中处理的图像?

时间:2016-02-19 09:37:30

标签: python html django

我有一个带有以下文件的Django应用程序:

models.py

class Document(models.Model):
    docfile = models.ImageField(upload_to='documents')

views.py

def Smaller(image):
    return image[0:32,0:32]

def upload(request):
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            newdoc = Document(docfile=request.FILES['docfile'])
            newdoc.save()
            image = get_object_or_404(Document, pk = newdoc.id)
            processed_image = Smaller(image.docfile.url)

我想在模板output.html中显示processed_image。

output.html

<img src="{{ _______ }}" alt="processed_image" style="width:384px;height:384px;border:0;" align = "center"/>

我还在render(request, 'output.html', {'input': image})作为最后一行返回upload(request),但当然它只适用于原始图片。

关于我如何做到这一点的任何建议?

0 个答案:

没有答案