- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
所以我有一个这样设置的 View :
class toi(FlaskView):
def index(self):
...
return render_template('home.html')
@route('/api/')
@route('/api/<int:urlgid>/')
@route('/api/<int:urlgid>/<int:urlper>/')
def APIInstruction(self, urlgid=None, urlper=None):
return render_template('toi-instructions.html')
然后在我的主 app.py 中我有
from views.toi import toi
toi.register(app)
然后在 toi:index 输出的 HTML 中我有
... <a href="{{ url_for('toi:APIInstruction') }}">how to use the API</a> ...
这给了我一个构建错误(没有更多细节),我一直在绞尽脑汁试图弄清楚这一点。如果我删除@routes,错误就会消失。如果我去掉第二个和第三个@routes,它不会给我一个构建错误。如果我将 urlgid 和 urlper 放入 url_for() 函数中,它不会改变任何内容。我尝试更改端点,尝试将 url_for 更改为 toi:api。
我不确定导致此 BuildError 的错误是什么。
最佳答案
当您对单个 View 使用多个路由时,会创建多个端点(每个路由一个端点)。为了帮助您区分每个端点,Flask-Classy 会在预期路由名称的末尾附加一个索引。从最后定义的路由开始,顺序为 0 到 n。所以给出你的例子:
@route('/api/') # use: "toi:APIInstruction_2"
@route('/api/<int:urlgid>/') # use: "toi:APIInstruction_1"
@route('/api/<int:urlgid>/<int:urlper>/') # use: "toi:APIInstruction_0"
def APIInstruction(self, urlgid=None, urlper=None):
return render_template('toi-instructions.html')
您可以在此处阅读有关此行为的更多信息: http://pythonhosted.org/Flask-Classy/#using-multiple-routes-for-a-single-view
或者(这是我更喜欢的方法),您可以指定要在任何 @route
装饰器中显式使用的端点。例如:
@route('/api/', endpoint='apibase')
可以使用以下方式访问:
url_for('apibase')
关于python - 当使用 url_for 链接到 @route 中带有变量的函数时,Flask-Classy 给出 BuildError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18885186/
我有一个缩小的 angular-class.min.js 文件,没有注释。除了对各个版本进行比较之外,有没有一种方法可以轻松判断 Angular Classy 的版本。正在被使用?可以在控制台中运行的
大家好,我正在另一个网站上研究幻灯片和推送菜单的示例,并且正在努力理解源下载中包含的 classie.js 文件中的 if 语句。 if ( 'classList' in document.docum
我正在使用 Flask + Flask-Classy 和 jinja2 模板,并且我想为该 View 中的所有请求(例如索引、获取等)将一些数据注入(inject)到我的模板中,而不必在每个请求上手动
我正在使用Classie.JS创建一个 s lideover menu demonstrated on Codrops 。 我正在使用的部分代码如下。我想实现一个回调,以便该函数的最后两行仅在切换完成
我的文件夹根 app.py 看起来像这样 import application if __name__ == '__main__': application.app.run() 我有一个名为 appl
在我的 Rails 应用程序中,我的折叠导航栏在滚动时没有改变它的样式,并且在检查元素控制台中也发生了错误: TypeError: elem is null elem.classList.
大家好,我下载了一些用 JS 编码的简单效果。该插件名为 classie.js,该人员编写了一些与此插件 classie.js 交互的自定义代码 前一段时间有人问过类似的问题classie.js
我正在为我的新 iOS 应用程序使用 Classy (www.classy.as) 我正在尝试弄清楚如何使用以下方法向 UILabel 添加阴影仅样式表。文档似乎没有提到这一点。我知道如何使用 CAL
我不久前设置了一个 Azure 备份保管库,并将我的系统备份到其中。备份保管库的类型为“备份保管库(经典)” 现在有一种新型的 Azure 备份保管库,可以在其他选项中启用警报。我需要利用这些选项。
所以我有一个这样设置的 View : class toi(FlaskView): def index(self): ... return ren
我查看了之前的问题,但没有涉及到我的确切问题。我认为自己是 html/css 的初学者 - 中级水平。我正在使用 html 和 css 开发一个基本的响应式页面,它根据媒体查询中的最大屏幕宽度交换图像
我是一名优秀的程序员,十分优秀!