首页 > 解决方案 > 我正在尝试从 html 页面中检索当前页码,以便在 update_table 函数上针对分页进行 url 路由

问题描述

我正在尝试从 html 页面中检索当前页码,以便在 update_table 函数上针对分页进行 url 路由。当我获取/打印 'page' 变量时,我不断得到None。有人可以帮我吗?

视图.py

@app.route('/')
@app.route('/<int:page_num>')
def index(page_num=1):
    historical_data = HR_historical.query.paginate(per_page=100, page=page_num, error_out=True)
    return render_template('index.html',historical_data = historical_data)

@app.route('/update-table/<int:id>', methods=['GET','POST'])
def update_table(id):
    updated = HR_historical.query.filter_by(id=id).first()
    form = Historical_Data_Form(obj=updated)
    if form.validate_on_submit():
        form.populate_obj(updated)
        db.session.add(updated)
        db.session.commit()
        **page = request.form.get('page')
        print(page)
        return redirect(url_for('index', page_num=page))**
    return render_template('edit_historical_table.html',form=form)

索引.html

<div class="pagination">
 <a href="{{url_for(request.endpoint, page_num=historical_data.prev_num)}}">&laquo;</a>
 {% for page in historical_data.iter_pages(left_edge=1, left_current=1, right_current=2, right_edge=1) %}
  <form class="" method="post">
   <input type="hidden" name="page" value="{{page}}">
  </form>
  {% if page %}
   <a href="{{url_for('index', page_num=page)}}">{{page}}</a>
  {% else %}
   <a href="#"<&laquo;</a>
   ...
  {% endif %}
 {% endfor %}
 <a href="{{url_for(request.endpoint, page_num=historical_data.next_num)}}">&raquo;</a>
</div>

标签: pythonflaskpagination

解决方案


推荐阅读