quick way to design large flask projects
Project description
Flask-XXL
- A best practices approach to creating larger web apps with Flask, in an attempt to make Flask feel like it is as capable, if not more, than Django.
to see this in a real world example take a look at my other projects Flask-Cms or Flask-Ide
What this provides:
-
Installable blueprints
- any blueprints listed in your settings under
BLUEPRINTS
will be imported and registered on your app
if that blueprint is a package, any files it contains namedmodels.py
orviews.py
will be imported as well,
so no more need to manualy import your views and models
giving odd errors if you dont do it in the exact correct order!!
- any blueprints listed in your settings under
-
basemodels.py
- with a sqlalchemy compatible BaseMixin class
- provides many useful CRUD operations, IE: model.save(), model.delete()
BaseMixin
generates__tablename__
automaticllyBaseMixin
adds an auto incrementingid
field, as the primary_key to each modelBaseMixin.session
is current model classes sessionBaseMixin.engine
is the current db engineBaseMixin.query
is the models sqlalchemy query from its sessionBaseMixin.get_all()
->
function to return all of a modelBaseMixin.get(*args,**kwargs)
->
get single model by attr values, mainly for id=x
-
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 or change whatever you need to ie: maybe based on logic that happens during request processing.
for 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 offlask.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_env -
BaseView.form_validated()
-> returns true if all forms validate -
namespaces imported into BaseView:
BaseView.flash == flask.flash
-
-
many builtin template globals(context_processors) to use. ie:
get_block(block_id)
<-- requires use of flask.ext.xxl.apps.blog
- add blocks of html/jinja2/template helpers into the db and access from within templates great for things like header navs or sidebar widgets
-
get_icon(icon_name,icon_lib)
<-- requires use of flask.ext.xxl.apps.blog- flask.ext.xxl.apps.blog comes with 8 icon librarys!!!
- Glyphicon
- Font Awesome
- Mfg_Labs
- Elusive icons
- Genericons
- and more ...
access any icon anywhere in your templates! even from cms blocks!!!
- flask.ext.xxl.apps.blog comes with 8 icon librarys!!!
-
get_model(model_name,blueprint_name)
- access any model class from any template (currently only supports sqlalchemy models)
-
get_button(name)
- create buttons in the cms and access from within templates
-
AppFactory class with many hooks into settings file (makes use of settings file similar to django)
- settings like:
- CONTEXT_PROCESSORS
- TEMPLATE_FILTERS
- URL_ROUTE_MODULES
- INSTALLED_BLUEPRINTS etc..
-
new revamped url routing scheme, use a urls.py file in each blueprint to define the url routes for the blueprint. reference the blueprint and the url route module in the settings file to registar onto the app upon instantiation.
define routes like this:
file: urls.py
from blueprint import blueprint from .views import ViewName,SecondView routes = [ ((blueprint_name,) ('/url',ViewName.as_View('view_name')), ('/another',SecondView.as_view('second_view')), ) ]
it basicly is like using
app.add_url_rule()
method, you just dont have to addview_func=ViewName.as_view(endpoint)
or at least theview_func=
part. -
easily start a new project or extend an old one
with the flaskxxl-manage.py command line helper tool-
to start a project from scratch
$ flaskxxl-manage.py start-project
-
to add to an existing project
$ flaskxxl-manage.py start-blueprint
-
for more fun checkout the wiki
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file flaskxxl-0.10.8.tar.gz
.
File metadata
- Download URL: flaskxxl-0.10.8.tar.gz
- Upload date:
- Size: 50.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93afd5d61f6b65b349892c2ce0c1a066eb3385190587649203b33938f164d9d6 |
|
MD5 | 5fb5520bcb0997a365909cf45a448fc5 |
|
BLAKE2b-256 | 4dd31bb35be050a62c3e028b02dd8e33d8dbc93dd2f61f1b27d836c82c71605a |