Python 忽略端点,冻结烧瓶丢失UrlGeneratorWarning?

Python 忽略端点,冻结烧瓶丢失UrlGeneratorWarning?,python,flask,wsgi,Python,Flask,Wsgi,我一直在努力让我想忽略某些端点,使这些URL在这个应用程序中保持动态而不是静态。是否有一种方法可以列出冻结烧瓶要忽略的端点 #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 t

我一直在努力让我想忽略某些端点,使这些URL在这个应用程序中保持动态而不是静态。是否有一种方法可以列出冻结烧瓶要忽略的端点

#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'])
#导入
app=烧瓶(名称)
冰柜=冰柜(无参数规则为False,日志url为False,应用程序为app)
app.config['FREEZER\u DESTINATION']='build'
#app-bluprint1(希望保持此项动态)
@app.route(“/app1/”)
@app.route(“/app1/”)
def app1(路径):
...
返回渲染模板(模板,页面=页面)
#app-2
@app.route('/app2/',默认值={'path':''})
@app.route(“/app2/”)
def app2(路径):
模板='app2/index.html'
页面='主页'
如果路径!='':
模板='/app2/%s.html'%path[-1]
页面=路径[:-1]
返回渲染模板(模板,页面=页面)
@冷冻机寄存器发生器
def handle_route():
打印“生成静态文件链接”
appDir=os.listdir('templates/app2')
对于appDir中的文件名:
如果文件名==“index.html”:
产生{'path':'''}
elif文件名!='base.html':
产生{'path':'%s/'%filenames[:-5]}
#app-bluprint3(希望保持动态)
@app.route('/app3/',默认值={'path':''})
@app.route(“/app3/”)
def app3(路径):
...
返回渲染模板(模板,页面=页面)
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
冷冻室
app.run(debug=app.config['debug'],port=app.config['port_NUMBER']))

我收到一个错误“MissingURLGeneratorWarning:终结点app1、app2的任何内容均未冻结。但是,我不想冻结这些终结点的任何内容。是否有方法关闭此警告?

是的,有两种:

  • 使用以下命令运行Python:

  • 在您的
    \uuuu主\uuuu
    条目中:

    if __name__ == '__main__':
        from warnings import simplefilter as filter_warnings
        filter_warnings('ignore', 'flask_frozen.MissingURLGeneratorWarning')
    

  • 最后,我有一些特定的参数要传递给静态或动态。因此,如果选择静态,则只定义了app2的@app.route,如果选择动态,则只定义了app1和app3的路由。
    if __name__ == '__main__':
        from warnings import simplefilter as filter_warnings
        filter_warnings('ignore', 'flask_frozen.MissingURLGeneratorWarning')