我在Python,Django框架中编写了以下代码:
class ImageGenerator:
def __init__(self, tip):
self.tip = tip
def remove_transparency(self, im, bg_colour=(250, 250, 250)):
if im.mode in ('RGBA', 'LA') or (im.mode == 'P' and 'transparency' in im.info):
alpha = im.convert('RGBA').split()[-1]
bg = Image.new("RGBA", im.size, bg_colour + (255,))
bg.paste(im, mask=alpha)
return bg
else:
return im
def generate(self):
print('Triggered')
border = 3
home_url = self.tip.fixture.home.image_url
away_url = self.tip.fixture.away.image_url
home_name = self.tip.fixture.home.name
away_name = self.tip.fixture.away.name
response = requests.get(home_url)
home = self.remove_transparency(Image.open(BytesIO(response.content)))
home_w, home_h = home.size
response = requests.get(away_url)
away = self.remove_transparency(Image.open(BytesIO(response.content)))
away_w, away_h = away.size
background_image = Image.open('/static/background.jpg', 'r')
当我执行此代码时,我收到以下错误:
FileNotFoundError at /fixtures/view/54848
[Errno 2] No such file or directory: '/static/background.jpg'
Request Method: POST
Request URL: http://127.0.0.1:8000/fixtures/view/54848
Django Version: 3.0.3
Exception Type: FileNotFoundError
Exception Value:
[Errno 2] No such file or directory: '/static/background.jpg'
Exception Location: /home/sander/.local/lib/python3.6/site-packages/PIL/Image.py in open, line 2809
Python Executable: /usr/bin/python3
Python Version: 3.6.9
Python Path:
['/home/sander/git/football',
'/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/home/sander/.local/lib/python3.6/site-packages',
'/usr/local/lib/python3.6/dist-packages',
'/usr/lib/python3/dist-packages']
Server time: Fri, 28 Feb 2020 18:56:54 +0000
我尝试使用.这将产生相同的错误。该命令也无法解决问题。staticfrom django.templatetags.static import staticcollectstatic
有人知道这个问题的解决方案吗?
12345678_0001
相关分类