我的用户可以上传自己的图片,并将其作为头像使用。现在,如果他们自己没有上传图像,我就很难检索默认的回退图像
头像的路径是“//mysite.com/avatar/username”
到目前为止,我有这段代码,当用户自己上传了一个头像时,它可以正常工作,但是当我尝试检索默认图像时,它给了我以下错误:
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: '/Users/myuser/Documents/github/mysite/static/images/profile.png'
def get(self):
path = self.request.path.split('/')
action = self.get_action(path)
if action:
e = employees.filter('username = ', action).get()
if e.avatar:
self.response.headers['Content-Type'] = "image/png"
self.response.out.write(e.avatar)
else:
self.response.headers['Content-Type'] = 'image/png'
path = os.path.join(os.path.split(__file__)[0], 'static/images/profile.png')
with open(path, 'r') as f:
print self.response.out.write(f.read())
我在app.yaml中将“/static”文件夹定义为静态目录
我知道我可以把profile.png放在根文件夹中,但我更喜欢放在“/static/images”文件夹中
有什么想法吗
如果将文件本身声明为
static_file
,或将其目录或其文件路径中的任何目录声明为应用程序/服务的.yaml
配置文件中的static_dir
,则默认情况下,应用程序代码无法访问该文件您还需要将其配置为
application_readable
。从Handlers element:相关问题 更多 >
编程相关推荐