O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding server endpoints

We will need two endpoints to make full use of our avatars – one to upload a new one, and one to fetch an avatar for a particular user.

Open up server.py and add the following functions:

@app.route("/update_avatar/<username>", methods=["POST"])def update_avatar(username):    img_b64 = request.form.get("img_b64")    database.update_avatar(username, img_b64)    return jsonify({        "success": True    })

This first endpoint will store the base64 encoded image data in the database against the username provided in the URL:

@app.route("/get_user_avatar/<username>")def get_avatar(username):    avatar_b64 = database.get_user_avatar(username)['avatar']    return jsonify({        "avatar": avatar_b64    })

The second endpoint will get the user's base64 encoded ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required