render_template中的可选关键字参数

丹尼尔斯0n

这是我的代码:

@app.route('/', methods=['GET', 'POST'])
def index():
    form = CryptoForm()
    if session.get('currency'):
        currency = session.get('currency')
        price1 = Get_info(currency)
        price = price1.get_filtered_data()
    if form.validate_on_submit():
        flash('success', 'success')
        currency = form.crypto.data
        get_price = Get_info(currency)
        session['currency'] = get_price.get_filtered_data()
        return redirect(url_for('index'))
    return render_template("index.html", form=form, price=price)

我正在尝试做的是让用户在表单中键入一个加密的首字母缩写词并提交。用户提交时,它应该显示价格。但是,当页面首次加载时,没有价格,因此price=priceinrender_template给我错误。我如何解决这个问题,以便仅在他提交表格后才有价格?

泰德·克莱恩·伯格曼

如果要提交表单或不提交表单,您想做其他事情,请检查表单是什么method

from flask import request

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'POST':
        # The user submitted something.
    else:
        # The user fetched something.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Seaborn Jointplot中的其他关键字参数

来自分类Dev

matplotlib radviz中的关键字参数

来自分类Dev

C扩展中的Ruby关键字参数

来自分类Dev

Python 3中的类“关键字参数”

来自分类Dev

Ruby关键字参数

来自分类Dev

Asyncio中的请求-关键字参数

来自分类Dev

模板参数中的const关键字

来自分类Dev

没有DEFAULT关键字的SQL UDF中的可选参数

来自分类Dev

Swift参数中的默认关键字

来自分类Dev

可选关键字参数和多参数练习

来自分类Dev

关键字和非关键字参数的顺序

来自分类Dev

参数c#中此关键字的用法

来自分类Dev

使用FD查找关系的候选关键字

来自分类Dev

忽略python中的其他关键字参数

来自分类Dev

在Ruby中跳过额外的关键字参数

来自分类Dev

在Julia中插值关键字参数

来自分类Dev

python click中的意外关键字参数

来自分类Dev

如何在Common Lisp中要求关键字参数?

来自分类Dev

render_template中的flask参数

来自分类Dev

在Racket中打包关键字参数?

来自分类Dev

Lambda中的自动参数类型导致“使用'template'关键字来对待...”错误

来自分类Dev

如何在关键字中为可选列表参数设置默认值

来自分类Dev

无关键字参数

来自分类Dev

程序需要2个参数以及带有关键字的可选参数

来自分类Dev

模板参数中的const关键字

来自分类Dev

使用FD查找关系的候选关键字

来自分类Dev

获取在python中具有特定关键字和其他可选关键字的推文

来自分类Dev

可选关键字参数-argparse

来自分类Dev

Dart 2 中可选关键字 new 的实用程序