introduction.txt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. 1 Introduction To Flask-Maple
  2. -----------------------------
  3. 1.1 Installation
  4. ~~~~~~~~~~~~~~~~
  5. To install Flask-Maple:
  6. .. code-block:: python
  7. pip install flask-maple
  8. Or alternatively, you can download the repository and install manually by doing:
  9. .. code-block:: python
  10. git clone git@github.com:honmaple/flask-maple.git
  11. cd flask-maple
  12. python setup.py install
  13. 1.2 Bootstrap
  14. ~~~~~~~~~~~~~
  15. It's very sample to use bootstrap
  16. .. code-block:: python
  17. from flask_maple import Bootstrap
  18. maple = Boostrap(app)
  19. or you can register it by
  20. .. code-block:: python
  21. maple = Bootstrap()
  22. maple.init_app(app)
  23. **Templates:**
  24. .. code-block:: html
  25. {% extends 'maple/base.html' %}
  26. {% block main -%}
  27. <button class="btn btn-primary">submit</button>
  28. <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
  29. {% endblock -%}
  30. **Config:**
  31. .. code-block:: python
  32. AUTHOR_NAME = "This will show you name at html footer"
  33. 1.3 Captcha
  34. ~~~~~~~~~~~
  35. Please install **Pillow** before use captcha
  36. .. code-block:: python
  37. pip install pillow
  38. **Usage**:
  39. .. code-block:: python
  40. from flask_maple import Captcha
  41. captcha = Captcha(app)
  42. Then you can visit `http://127.0.0.1/captcha <http://127.0.0.1/captcha>`_
  43. **Config**:
  44. .. code-block:: python
  45. CAPTCHA_URL = "The captcha url,default 'captcha'"
  46. 1.4 Error
  47. ~~~~~~~~~
  48. You don't register app.errorhandler if you use error extension
  49. **Usage**:
  50. .. code-block:: python
  51. from flask_maple import Error
  52. error = Error(app)
  53. This extension provides some simple error view
  54. .. code-block:: python
  55. 404
  56. 403
  57. 500
  58. 1.5 Login
  59. ~~~~~~~~~
  60. It's easy to use login
  61. .. code-block:: python
  62. class User(db.Model, UserMixin):
  63. id = db.Column(db.Integer, primary_key=True)
  64. username = db.Column(db.String(80), unique=True)
  65. email = db.Column(db.String(120), unique=True)
  66. password = db.Column(db.String(120), unique=True)
  67. def __repr__(self):
  68. return '<User %r>' % self.username
  69. @staticmethod
  70. def set_password(password):
  71. pw_hash = generate_password_hash(password)
  72. return pw_hash
  73. def check_password(self, password):
  74. return check_password_hash(self.password, password)
  75. **Usage**:
  76. .. code-block:: python
  77. from flask_maple import Auth
  78. auth = Auth(app, db=db, mail=mail, user_model=User)
  79. If you use flask-principal,please set use_principal = True
  80. .. code-block:: python
  81. from flask_maple import Auth
  82. auth = Auth(app, db=db, mail=mail, user_model=User,use_principal = True)
  83. then you can visit `http://127.0.0.1:5000/login <http://127.0.0.1:5000/login>`_