用Flask+Jinja去实现微信的公众号
但是对于:
/Users/crifan/dev/dev_root/daryun/SIPEvents/sourcecode/flask/sipevents/templates/index.html
<a href="{{ url_for(‘show_event’, event_id = expiredEvent.id, curUserOpenid = curUser.openid) }}" class="item-link item-content"> |
/Users/crifan/dev/dev_root/daryun/SIPEvents/sourcecode/flask/sipevents/views.py
@app.route(‘/show_event/<int:event_id>’, methods=[‘GET’]) def show_event(event_id): requestMethod = request.method requestArgs = request.args gLog.debug(‘requestMethod=%s, requestArgs=%s’, requestMethod, requestArgs) gLog.debug(‘type(event_id)=%s, event_id=%s’, type(event_id), event_id) # eventId = request.args.get("eventId", "") eventId = event_id gLog.debug(‘type(eventId)=%s, eventId=%s’, type(eventId), eventId) # curUserOpenid = request.args.get("curUserOpenid", "") # gLog.debug(‘curUserOpenid=%s’, curUserOpenid) #if eventId != "": if eventId != 0: curEvent = Event.query.filter_by(id=eventId).first() gLog.debug(‘curEvent=%s’, curEvent) if curEvent : return render_template("showEvent.html", curEvent=curEvent) else: gLog.error("can not find valid event for eventId=%s", eventId) else: gLog.error("Error: Empty event id!") |
然后虽然是可以正常显示html页面了:
但是,此处,如果去拷贝微信的页面的地址时:
右上角三个点-》复制链接
结果拷贝出来的网页地址却是:
之前的地址:
http://hd.webonn.com/?code=01174Yxr1Uxvus0ebLwr1Bl1yr174Yxn&state=
而不是我此处所希望的:
http://hd.webonn.com/show_event/2
此处,希望不论是Flask还是Jinja中,如何在调用此处的show_event/2
的路由的时候:
url_for(‘show_event’, event_id = expiredEvent.id, curUserOpenid = curUser.openid)
还是渲染显示页面:
return render_template("showEvent.html", curEvent=curEvent)
的时候,可以把对应的
网页的地址,换成:
http://hd.webonn.com/show_event/对应的ID的数字
flask url_for change page url
flask jinja change page url
jinja change url
jinja2 – Flask: current page in request variable – Stack Overflow
jinja redirect url
python – How to route user to another url Jinja – Stack Overflow
Template Designer Documentation — Jinja2 Documentation (2.8-dev)
python – Creating link to an url of Flask app in jinja2 template – Stack Overflow
python – Jinja – Is there any built-in variable to get current HTML page name? – Stack Overflow
jinja change url
jinja html url
Flask 如何改变网页地址
Flask 如何改变URL
Flask jinja redirect
[基本解决]Flask中用redirect和url_for跳转到URL但是网页中的url地址没有变化
[总结]
目前没有完全解决,有空继续去找完美解决的办法。
转载请注明:在路上 » [基本解决]如何在Flask或Jinja中实现更新微信的网页的地址