Previous question about choosing only specific files to freeze。
我一直在尝试使用Frozen-Flask来忽略某些端点,以使这些URL保持动态而不是静态。有没有办法让Frozen-Flask的端点列表被忽略。
#imports
app = Flask(__name__)
freezer = Freezer(with_no_argument_rules = False, log_url_for = False, app = app)
app.config['FREEZER_DESTINATION'] = 'build'
#app-bluprint1 (Want to keep this one dynamic)
@app.route('/app1/')
@app.route('/app1/<path:path>/')
def app1(path):
...
return render_template(template, page = page)
#app-bluprint2
@app.route('/app2/', defaults = {'path': ''})
@app.route('/app2/<path:path>')
def app2(path):
template = 'app2/index.html'
page = 'home'
if path != '':
template = '/app2/%s.html' %path[-1]
page = path[:-1]
return render_template(template, page = page)
@freezer.register_generator
def handle_route():
print "Generating Static Files Links"
appDir = os.listdir('templates/app2')
for filenames in appDir:
if filenames == 'index.html':
yield {'path': ''}
elif filenames != 'base.html':
yield {'path': '%s/' % filenames[:-5]}
#app-bluprint3 (Want to keep this dynamic)
@app.route('/app3/', defaults = {'path': ''})
@app.route('/app3/<path:path>')
def app3(path):
...
return render_template(template, page = page)
if __name__ == '__main__':
freezer.freeze()
app.run(debug=app.config['DEBUG'], port=app.config['PORT_NUMBER'])
我收到错误&#34; MissingURLGeneratorWarning:端点app1,app2没有冻结。但是,我不想冻结这些端点的任何内容。有没有办法关闭此警告?
答案 0 :(得分:0)
是的,有一对:
使用the -W
flag运行Python:
python -W ignore:'.*':flask_frozen.MissingURLGeneratorWarning
__main__
条目中if __name__ == '__main__':
from warnings import simplefilter as filter_warnings
filter_warnings('ignore', 'flask_frozen.MissingURLGeneratorWarning')