从Flask中的配置更改静态文件夹 [英] Change static folder from config in Flask
本文介绍了从Flask中的配置更改静态文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人尝试过基于烧瓶配置的静态文件夹代码片段吗?
代码:
import flask
class MyFlask(flask.Flask):
@property
def static_folder(self):
if self.config.get('STATIC_FOLDER') is not None:
return os.path.join(self.root_path,
self.config.get('STATIC_FOLDER'))
@static_folder.setter
def static_folder(self, value):
self.config.get('STATIC_FOLDER') = value
# Now these are equivalent:
app = Flask(__name__, static_folder='foo')
app = MyFlask(__name__)
app.config['STATIC_FOLDER'] = 'foo'
在我的情况下,抱怨此行:
In my case in complains about this line:
self.config.get('STATIC_FOLDER') = value
错误消息:Can't assign to function call
有人可以从Flask的config.py文件中设置static_folder吗?
Does anyone how to set the static_folder from the config.py file in Flask?
推荐答案
我对该代码段一无所知,但是
I don't know anything about that snippet, but
some_function(...) = some_value
永远不是有效的Python(Python没有 l值).看起来config
具有类似dict的界面,所以令人反感的行可能应该只是
is never valid Python (Python doesn't have l-values). It looks like config
has a dict-like interface, so the offending line should probably just be
self.config['STATIC_FOLDER'] = value
setter上方的getter定义可能存在复制和粘贴错误.
Probably a copy-and-paste error from the getter definition above the setter.
这篇关于从Flask中的配置更改静态文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文