从https://en.gravatar.com/获得头像
from flask import Flask, render_template from flask_avatars import Avatars
app = Flask(name) avatars = Avatars(app)
@app.route('/') def index(): email_hash = hashlib.md5('test@helloflask.com'.lower().encode('utf-8')).hexdigest() return render_template('index.html', email_hash=email_hash)
html
<p>{% raw %}{{ avatars.gravatar(email_hash) }}{% endraw %}: <img src="{{ avatars.gravatar(email_hash) }}"></p> <p>{% raw %}{{ avatars.gravatar(email_hash, size='200', default='monsterid') }}{% endraw %}: <img src="{{ avatars.gravatar(email_hash, size='200', default='monsterid') }}"></p>