折腾:
[基本解决]如何在Flask或Jinja中实现更新微信的网页的地址
想要实现:
Flask中在调用:
redirect(url_for(‘show_event_page’, event_id=event_id))
的时候,
跳转到对应的url,且同时网页中的url地址也变成对应的
show_event_page/event_id
用代码:
@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) #return redirect(url_for(‘show_event_page’, curEvent=curEvent)) return redirect(url_for(‘show_event_page’, event_id=event_id)) # else: # gLog.error(“can not find valid event for eventId=%s”, eventId) else: gLog.error(“Error: Empty event id!”) @app.route(‘/show_event_page/<int:event_id>’, methods=[‘GET’]) def show_event_page(event_id): gLog.debug(“event_id=%s”, event_id) curEventId = event_id curEvent = Event.query.filter_by(id=curEventId).first() gLog.debug(‘curEvent=%s’, curEvent) # return render_template(“showEvent.html”, curEvent=curEvent) if curEvent: return render_template(“showEvent.html”, curEvent=curEvent) else: gLog.error(“can not find valid event for curEventId=%s”, curEventId) |
最后拷贝出来的url地址还是旧的。
Flask change url
python – Redirecting to URL in Flask – Stack Overflow
是用的:
flask.redirect(location, code=302)
但还是没有改变网页的url地址啊
Redirects in Flask/Werkzeug are not changing the URL – Stack Overflow
那现在我此处,用的不是jquery-mobile
而是Framework7
所以要去找Framework7中,如何更新url地址
[基本解决]Framework7中在页面跳转后如何更新页面的url地址
转载请注明:在路上 » [基本解决]Flask中用redirect和url_for跳转到URL但是网页中的url地址没有变化