Profile Page and Avatars
@app.route('/user/
@login_required
def user(username):
user = User.query.filter_by(username=username).first_or_404()#查找username的第一条记录,找不到的话返回error 404
posts = [
{'author': user, 'body': 'Test post #1'},
{'author': user, 'body': 'Test post #2'}
]
return render_template('user.html', user=user, posts=posts)
Gravatar(个人全球统一标识;) service提供图片
#获得个人的Gravatar URL
from hashlib import md5
'https://www.gravatar.com/avatar/' + md5(b'john@example.com').hexdigest()
https://www.gravatar.com/avatar/729e26a2a2c7ff24a71958d4aa4e5f35
https://www.gravatar.com/avatar/729e26a2a2c7ff24a71958d4aa4e5f35?s=128 #设置图片尺寸
Gravatar service只支持小写字母的邮箱,MD5支持python下的Bytes,不支持string
{% include '_post.html' %}#把_post.html包含进来,即一个模板包含另一个模板
@app.before_request