To install Flask-Avatar:
pip install flask-avatar
Or alternatively, you can download the repository and install manually by doing:
git clone git@github.com:honmaple/flask-avatar.git
cd flask-avatar
python setup.py install
from flask_avatar import Avatar
[...]
Avatar(app)
# or use cachefunc
Avatar(app, cache=cachefunc)
cachefunc must be a decorator: example:
def cachefunc(func):
@wrap(func)
def _cache(*args, **kwargs):
r = cacheclient.get("cache key")
if r is not None:
return r
return func(*args, **kwargs)
return _cache
Templates:
{{ url_for('avatar',text = user.username )}}
or set width with:
{{ url_for('avatar',text = user.username,width=60)}}
AVATAR_URL = '/avatar' #The avatar url,default '/avatar/<text>/<width>'
AVATAR_RANGE = [0,512] #set avatar range to allow generate,if disallow,abort(404).Default [0,512]