Django排行榜(记分板)应用程序,使用Redis作为后端
django-leaderboard的Python项目详细描述
Django排行榜(记分板)应用程序,使用Redis作为后端。此应用程序是python排行榜api的包装https://github.com/agoragames/python-leaderboard
该应用程序使用redis kvs作为其后端,并将分数存储在其“排序集”数据结构中,该结构保持数据的顺序,并允许我们有效地检索、更新和删除分数。
使用此应用程序,您可以获得分页排行榜、创建分数、更新或删除分数。甚至在给定的分数上获得排名。
功能
- RESTful api for creating, updating, deleting and retrieving high scores or scores around the user
- Standard view for displaying high scores with pagination
未实现的功能
- delete method for the api
要求
python leaderboard modulepip install leaderboard,注意该模块将安装redis和hiredis模块作为其依赖项。 djangorestframeworkpip安装djangorestframework以提供rest行为。
安装
Add the django_leaderboard folder to your path.
Add django_leaderboard to APPS list in settings.py
Make sure that your redis server is running.
Add following lines to your urls.py file.
Run python manage.py runserver to test it out.
url(r’^leaderboard/’, include(‘django_leaderboard.urls’)), # auth support for rest framework url(r’^restframework’, include(‘djangorestframework.urls’, namespace=’djangorestframework’))
用法
感谢djangorestframeword,您只需访问http://localhost:8000/leaderboard/api/<;game identifier>;/即可创建、更新或获取排行榜。
其他URL分别是http://localhost:8000/leaderboard/api/<;game identifier>;/user/<;user id>;/和http://localhost:8000/leaderboard/api/<;game identifier>;/<;page id>;/用于分页。请参见urls.py查看完整列表或url。
要使用api创建新的排名,请向http://localhost:8000/leaderboard/api/<;game identifier>;/发送post请求。游戏标识符是决定你的游戏系统的关键。它可以是任何东西。参数是用户id和score。 要查看排行榜的HTML表格,请转到http://localhost:8000/leaderboard/highscores/<;game identifier>;/页面。
示例
在源代码中有一个示例项目,使其易于启动。
贡献
请随意贡献。