python - 我正在尝试从 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)}}">«</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="#"<«</a>
...
{% endif %}
{% endfor %}
<a href="{{url_for(request.endpoint, page_num=historical_data.next_num)}}">»</a>
</div>
解决方案
推荐阅读
- dialogflow-es - 在对话流中获得多个意图匹配
- python - 用 K-Means 聚类并重塑为彩色图像
- python - Python:无法导入名称 ss
- node.js - NodeJs/React - Multer 上传多个文件
- oracle11g - Oracle DBlink 能够访问除 1 个表之外的所有表
- selenium-webdriver - 如何手动或通过使用 selenium 的自动化处理验证码图像?
- .htaccess - htaccess 有什么问题?
- python - Windows 中 Python3.7 的主管(或类似工具)
- javascript - 如何使用键值对象作为 Angular Material 表的数据源
- r - 如何循环从多个光栅文件中提取值?