flask-xxl - 构建大型网络应用, 来令 flask 感觉象 Django
jopen
10年前
以最佳实践的形式来指引如何构建大型网络应用, 来让 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
-