我正在尝试使用这个答案来解决我的问题,但我不知道如何正确使用它。
我的代码:
应用程序=烧瓶(名称)
app = Flask(__name__, static_folder="static", static_path="")
class SecuredStaticFlask(app):
def send_static_file(self, filename):
# Get user from session
if current_user.is_authenticated():
return super(SecuredStaticFlask, self).send_static_file(filename)
else:
abort(403)
当我http://localhost:5000/some_existing_file
在浏览器中访问时,Flask 给我一个错误:
Traceback (most recent call last):
File "/home/honza/Stažené/pycharm-community-3.0/helpers/pydev/pydevd.py", line 1498, in <module>
debugger.run(setup['file'], None, None)
File "/home/honza/Stažené/pycharm-community-3.0/helpers/pydev/pydevd.py", line 1139, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "/home/honza/workspace/web_development/login/toneid_web_api_jk.py", line 37, in <module>
class SecuredStaticFlask(app):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 507, in __init__
self.add_url_rule(self.static_url_path + '/<path:filename>',
TypeError: Error when calling the metaclass bases
can only concatenate tuple (not "str") to tuple
flask.Flask 的实例是app
,对吗?所以,我认为 Flask 的子类是subclass_name(parent_class)
.
有谁能够帮我?谢谢。