我在我的 python 应用程序中使用 Flask。现在我正在转向 Web2py。
我很困惑 Flask 的 app.config
在 Web2py 中的位置。
例如:
app.config['FOLDER'] = 'new/'
我遇到麻烦的其他事情是什么
Web2py 中 Flask 的redirect(url_for('file', filename=filename))
。在此,我重定向到函数 file
,并以 file_name
作为参数
感谢您的帮助。
最佳答案
web2py 的工作方式与 Flask 不同,因此您可能需要浏览 web2py 文档才能了解如何使用它。 web2py 没有与 Flask 的 app.config
完全类似的东西。至于重定向功能,请注意路由在 web2py 中的工作方式不同。特别是, Controller 操作不采用命名参数。相反,函数名称后面的 URL 段可在 request.args
中使用。 ,查询字符串参数可在 request.get_vars
中找到。 (以及 request.vars
,其中还包括 request.post_vars
中的变量)。因此,web2py 中的类似代码将是:
redirect(URL('mycontroller', 'file', args=filename))
在 Controller 中:
def file():
filename = request.args(0)
或者,您可以输入 filename
在查询字符串中:
redirect(URL('mycontroller', 'file', vars=dict(filename=filename)))
在这种情况下,它将在request.vars.filename
中可用。而不是request.args(0)
.
关于python - web2py 中的应用程序配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21626167/