-1
I have a Flask page, and wanted to know how to make only my page access the files from Static I have a handling of files from Static (for image resizing):
@app.route('/static/<folder>/<filename>.<ext>', methods=['get'])
def file(folder, filename, ext):
if not ext in ['jpeg', 'jpg', 'gif', 'png']:
try:
with open(f'static/{folder}/{filename}.{ext}') as fp:
lines = fp.readlines()
lines = '\n'.join(lines)
if ext in ['js', 'json']:
mime = 'application'
else:
mime = 'text'
ext.replace('js', 'javascript')
return Response(lines, mimetype=f'{mime}/{ext}')
except FileNotFoundError:
abort(404)
try:
im = Image.open(f'static/{folder}/{filename}.{ext}').convert('RGBA')
if request.args.get("size"):
size = int(request.args.get("size"))
im.thumbnail((size, size), Image.ANTIALIAS)
except FileNotFoundError:
abort(404)
return pil_image(im, ext)
I wanted to know if there is a way in it, or in some other way, only let the page access Static (by hrefs, srcs... but never by the url)
I suggest you read the community guidelines on how to make a good question.
– user148754
In particular, never, never, post code as image. Put code as text. An image cannot be cut and pasted by someone who wants to play their program to find a good answer. Also, words within the image are not visible by the search engines of the site: all the text there is essentially invisible.
– jsbueno