项目作者: aiscenblue

项目描述 :
Sanic framework application boilerplate project
高级语言: Python
项目地址: git://github.com/aiscenblue/sanic-framework-starterkit.git
创建时间: 2017-10-20T20:00:48Z
项目社区:https://github.com/aiscenblue/sanic-framework-starterkit

开源协议:MIT License

下载


Requirements:

  1. Python 3.5 or higher
  2. Windows Environment: N/A

Install requirements
pip3 install -r requirements.txt

Setup configuration

  1. open: config/app.py
  2. HOST = "0.0.0.0"
  3. DEBUG = True / False
  4. PORT = 8000
  5. WORKERS = 4 # workers: Number of processes received before it is respected

RUN sanic
python3 run.py

  1. 2017-09-25 10:52:54 - (sanic)[DEBUG]:
  2. ▄▄▄▄▄
  3. ▀▀▀██████▄▄▄ _______________
  4. ▄▄▄▄▄ █████████▄ / \
  5. ▀▀▀▀█████▌ ▀▐▄ ▀▐█ | Gotta go fast! |
  6. ▀▀█████▄▄ ▀██████▄██ | _________________/
  7. ▀▄▄▄▄▄ ▀▀█▄▀█════█▀ |/
  8. ▀▀▀▄ ▀▀███ ▄▄
  9. ▄███▀▀██▄████████▄ ▄▀▀▀▀▀▀█▌
  10. ██▀▄▄▄██▀▄███▀ ▀▀████ ▄██
  11. ▄▀▀▀▄██▄▀▀▌████▒▒▒▒▒▒███ ▌▄▄▀
  12. ▐▀████▐███▒▒▒▒▒▐██▌
  13. ▀▄▄▄▄▀ ▀▀████▒▒▒▒▄██▀
  14. ▀▀█████████▀
  15. ▄▄██▀██████▀█
  16. ▄██▀ ▀▀▀
  17. ▄█ ▐▌
  18. ▄▄▄▄█▌ ▀█▄▄▄▄▀▀▄
  19. ▀▀▄▄▄▀
  20. ▀▀▄▄▀
  21. 2017-09-25 10:52:54 - (sanic)[INFO]: Goin' Fast @ http://0.0.0.0:8000
  22. 2017-09-25 10:52:54 - (sanic)[INFO]: Starting worker [24478]
  23. 2017-09-25 10:52:54 - (sanic)[INFO]: Starting worker [24479]
  24. 2017-09-25 10:52:54 - (sanic)[INFO]: Starting worker [24480]
  25. 2017-09-25 10:52:54 - (sanic)[INFO]: Starting worker [24481]

Register blueprint route

NOTE :: if it's a sub directory it must consist a __init__.py file to be recognize as a package

  1. from sanic import Blueprint
  2. from sanic.response import json
  3. from http import HTTPStatus
  4. """ blueprint module for url handler """
  5. module_name = 'index' # module name to be registered in the blueprint
  6. or just change the 'index' string to get_file_name(__file__)
  7. it uses the current filename as the root url of your api module
  8. module_name = get_file_name(__file__)
  9. method = Blueprint(module_name, url_prefix='/')
  10. """ http code status """
  11. __status = HTTPStatus # status codes library
  12. @method.route("/", methods=['GET'])
  13. async def index(requests):
  14. return json("Welcome to sanic!", __status.OK)

READ MORE: https://github.com/channelcat/sanic/