python - Flask User Page with ID -
i want have user page (/users/). when open /users/, should see own user profile (if logged in, else: error) when giev command, /users/?uid=2999 should laod user info of user uid=2999. works, if signed in see own profile works too. if not signed in, there following error:
bad request browser (or proxy) sent request server not understand.
that's code snippet:
@app.route('/users/') def users(): if 'logged_in' in session: ret = 0 user = session['uid'] c, conn = dbconnect.conn() data = c.execute("select * users uid = (%s)", (user)) if int(data) == 0: flash("error! please send report @ martin@tekkkz.com!") else: data = c.fetchone() ret = 1 c.close() conn.close() gc.collect() if ret: return render_template("users.html", nav=2, user=data) elif request.args['uid']: ret = 0 user = request.args['uid'] c, conn = dbconnect.conn() data = c.execute("select * users uid = (%s)", (user)) if int(data) == 0: flash("invalid user-id. user doesn't exist!") else: data = c.fetchone() ret = 1 c.close() conn.close() gc.collect() if ret: return render_template("users.html", nav=2, user=data) else: flash("you need logged in see own profile!") return redirect(url_for('login'))
why there bad reqquest
error ?
the problem line, when not logged in, , 'uid' not in query string.
elif request.args['uid']:
flask raises http error when fails find key in args.
instead should have
elif 'uid' in request.args:
Comments
Post a Comment