GithubHelp home page GithubHelp logo

jstacoder / flask-xxl Goto Github PK

View Code? Open in Web Editor NEW
387.0 20.0 21.0 195 KB

A best practices approach to creating large web apps, which gives the ease and power of django to your flask app

Python 59.46% HTML 40.54%

flask-xxl's Introduction

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.

this is an amazing program best in the world PyPI version

Get help on Codementor

Join the chat at https://gitter.im/jstacoder/flask-xxl

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 named models.py or views.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!!
  • basemodels.py

    • with a sqlalchemy compatible BaseMixin class
    • provides many useful CRUD operations, IE: model.save(), model.delete()
    • BaseMixin generates __tablename__ automaticlly
    • BaseMixin adds an auto incrementing id field, as the primary_key to each model
    • BaseMixin.session is current model classes session
    • BaseMixin.engine is the current db engine
    • BaseMixin.query is the models sqlalchemy query from its session
    • BaseMixin.get_all() -> function to return all of a model
    • BaseMixin.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 of flask.helpers.redirect which allows you to directly enter the endpoint, so you dont have to run it through url_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!!!

    • 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 add view_func=ViewName.as_view(endpoint) or at least the view_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

Bitdeli Badge

for more fun checkout the wiki

flask-xxl's People

Contributors

bitdeli-chef avatar dankrsihu avatar gitter-badger avatar jstacoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flask-xxl's Issues

how to create a new project?

โžœ ox flaskxxl-manage.py start_project
not testing, are you sure you want to continue... [n]: n
โžœ ox flaskxxl-manage.py start_project
not testing, are you sure you want to continue... [n]: y
Configuration provided:
[variables] from ~/.mrbob
[variables] from --config file
[defaults] from ~/.mrbob
[defaults] from --config file
[mr.bob] from ~/.mrbob
[mr.bob] from --config file
[mr.bob] from command line interface
non_interactive = False
quiet = False
remember_answers = True
verbose = True

usage: flaskxxl-manage.py [-h] [-O TARGET_DIRECTORY] [-v] [-c CONFIG] [-V]
[-l] [-w] [-n] [-q]
[template]
flaskxxl-manage.py: error: ConfigurationError: Template directory does not exist: /Library/Python/2.7/site-packages/flask_xxl-0.4.5-py2.7.egg/flask_xxl/templates/project

python 3.x (3.5) compatibility

Lot's of prints without parenthesis for example which cause issues. also dependencies which are part of the standard library and shouldn't need to be declared (argparse, wsgiref.)

No module named flask_xxl.cli

OS: MAC OS Mavericks

Installation step:

  1. git clone
  2. python setup.py install
    Installation is successful.

When using flask-xxl via "flaskxxl-manage.py start-project", error occurred.
Traceback (most recent call last):
File "/usr/local/bin/flaskxxl-manage.py", line 9, in
load_entry_point('flask-xxl==0.0.7-', 'console_scripts', 'flaskxxl-manage.py')()
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 356, in load_entry_point
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 2439, in load_entry_point
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 2155, in load
ImportError: No module named flask_xxl.cli

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.