https://github.com/honmaple/flask-avatar
To generate avatar for flask
https://github.com/honmaple/flask-avatar
Last synced: about 1 year ago
JSON representation
To generate avatar for flask
- Host: GitHub
- URL: https://github.com/honmaple/flask-avatar
- Owner: honmaple
- License: bsd-3-clause
- Created: 2016-07-02T10:23:13.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-03-03T13:42:18.000Z (over 8 years ago)
- Last Synced: 2025-03-20T16:51:55.758Z (over 1 year ago)
- Language: Python
- Size: 2.2 MB
- Stars: 8
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
* flask-avatar
[[https://pypi.python.org/pypi/Flask-Avatar][https://img.shields.io/badge/pypi-v0.1.2-brightgreen.svg]]
[[https://pypi.python.org/pypi/Flask-Avatar][https://img.shields.io/badge/python-3.4-brightgreen.svg]]
[[LICENSE][https://img.shields.io/badge/license-BSD-blue.svg]]
** Example
[[https://raw.githubusercontent.com/honmaple/flask-avatar/master/example/avatar1.png]]
[[https://raw.githubusercontent.com/honmaple/flask-avatar/master/example/avatar2.png]]
[[https://raw.githubusercontent.com/honmaple/flask-avatar/master/example/avatar3.png]]
** Installation
To install Flask-Avatar:
#+BEGIN_SRC shell
pip install flask-avatar
#+END_SRC
Or alternatively, you can download the repository and install manually by doing:
#+BEGIN_SRC sehll
git clone git@github.com:honmaple/flask-avatar.git
cd flask-avatar
python setup.py install
#+END_SRC
** Usage
#+BEGIN_SRC python
from flask_avatar import Avatar
[...]
Avatar(app)
# or use cachefunc
Avatar(app, cache=cachefunc)
#+END_SRC
*cachefunc* must be a decorator:
example:
#+BEGIN_SRC python
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
#+END_SRC
Templates:
#+BEGIN_SRC html
{{ url_for('avatar',text = user.username )}}
#+END_SRC
or set *width* with:
#+BEGIN_SRC html
{{ url_for('avatar',text = user.username,width=60)}}
#+END_SRC
** Config
#+BEGIN_SRC python
AVATAR_URL = '/avatar' #The avatar url,default '/avatar//'
AVATAR_RANGE = [0,512] #set avatar range to allow generate,if disallow,abort(404).Default [0,512]
#+END_SRC
** Thanks to
[[https://github.com/maethor/avatar-generator][https://github.com/maethor/avatar-generator]]