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

posted @ 2018-03-21 20:17  blog_hfg  阅读(147)  评论(0)    收藏  举报