flask-xxl - 構建大型網絡應用, 來令 flask 感覺象 Django
以最佳實踐的形式來指引如何構建大型網絡應用, 來讓 flask 感覺象 Django.
What this provides:
-
basemodels.py
- with a BaseMixin class that provides many useful CRUD operations, IE: model.save(), model.delete()
-
baseviews.py
- with a BaseView class that is subclassed from Flask.views.MethodView to allow easy definition of view responses to get and post requests.
-
BaseView also has many builtin helpers/imports to speed development, ie:
-
BaseView.render() calls render_template(BaseView._template,**BaseView._context) easily define either or both in the class variable section of the class and then add,change/ w/e based on logic that happens during request processing. example:
class ExampleView(BaseView): _context = { 'some_flag':True, } def get(self,new_flag=False): if new_flag: self._context['new_flag'] = new_flag self._context['some_flag'] = False return self.render()
-
BaseView.redirect(endpoint) is a reimplementation of
flask.helpers.redirect
which allows you to directly enter the endpoint, so you dont have to run it throughurl_for()
first. BaseView.get_env()
returns the current jinja2_envBaseView.form_validated()
returns true if all forms validate-
namespaces imported into BaseView: BaseView.flash == flask.flash
-
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!