【问题标题】:how can i get html anchor tag id attribute in python function in flask [duplicate]我如何在烧瓶中的python函数中获取html锚标签id属性[重复]
【发布时间】:2020-02-26 17:46:09
【问题描述】:

部分html脚本:

<a href="/author_profile" id="{{record[0]}}">{{record[1]}}</a>

python 代码:

@app.route('/author_profile')
  def author_profile():
     id=request.args['id']
     return render_template('author_profile.html',id=id)

如何获取flask模块中anchor标签的id?

【问题讨论】:

    标签: python flask


    【解决方案1】:

    在路由中添加&lt;int:id&gt;参数,并使用url_for生成带有id值的URL。

    <a href="{{ url_for('author_profile', id=record[0]">{{record[1]}}</a>
    
    @app.route('/author_profile/<int:id>')
    def author_profile(id):
        author = Author.query.get(id)
        return render_template('author_profile.html', author=author)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-09
      • 2020-08-02
      • 2015-06-05
      • 1970-01-01
      相关资源
      最近更新 更多