如何从python将图像保存在django媒体根存储中

问题描述 投票:0回答:1

嗨,有人帮我解决这个问题,我想将我的图像保存到媒体根文件夹中,我在媒体文件夹中命名了图片。这是我的代码,我希望我的函数在制作屏幕快照时都应如此将屏幕快照保存在我的媒体根文件夹中

from django.shortcuts import render
from django.http import HttpResponse
from django.shortcuts import get_object_or_404,render,redirect
import time 
import random
from django.db import models
import pyautogui
import sys
from shots.models import pictures
from .models import pictures
from shots.forms.forms import DocumentForm

def button(request):
    import pyautogui
    myScreenshot = pyautogui.screenshot()
    storage=pictures.pictures2
    myScreenshot.save(storage)

    return render(request,'index.html')

def output(request):
    return HttpResponse("""Hello, world. You're at the polls index.
    your Screenshot should start now""")```


this is my models.py

从django.db导入模型随机导入

类图片(models.Model):pub_date = models.DateTimeField('发布日期')图片2 =模型.ImageField(upload_to ='图片')```

python django
1个回答
0
投票

您会发现this answer很不幸。

© www.soinside.com 2019 - 2024. All rights reserved.