Comments (10)
I'm currently playing with the idea to add a module object for largish applications:
admin = app.module('admin', url_prefix='/admin')
@admin.route('/login')
def login():
return 'Blafsel'
And then url_for('admin.index')
returns the URL to the admin and the @admin.route
decorated functions are prefixed with what is set as url_prefix
.
from flask.
I like this - similar to what I was doing with my routes changes but much better.
from flask.
I did sketch something up in a branch: http://github.com/mitsuhiko/flask/tree/module-support
That does something similar to what is mentioned above. Check out the test for an idea how it works. Because it totally breaks compat with 1.0 i have not updated anything yet.
I am totally for breaking support with 0.1 but in order to keep the docs easy to understand there should not be "versionchanged" things all over the place. Have to think about something for the docs.
from flask.
Not sure where I posted this the first time...
http://github.com/cgrinds/flask/tree/module-work
I don't accumulate the module routes, I just add them directly, which makes the code simpler.
I do this by not creating a module directly but asking the app for one. Instead of:
admin = flask.Module('admin', url_prefix='/admin')
admin = app.register_module('admin') # the url_prefix defaults to /name
other than that, it's all the same
from flask.
I did that first, but the problem is that that way you can't have fully pluggable applications. What my code does currently is postponing that so that you can do "from someapplication import the_module" and then register it with your app.
from flask.
That makes sense, I wasn't thinking of the interface or test as "from someapplication import the_module". The later the binding, the better, especially on GAE otherwise startup will kill ya.
So your design allows modules to be completely self-contained - flask reaches inside of the module and pulls out the routes. With my design there is no way to pass the app to the module when it's imported.
from flask.
I've had a chance to play with the module-support branch. It's very intuitive, and as mitsuhiko points out allows you to create plugins quite easily - just expose the views as a Module instance and import the module when you are building the app. It gets around the circular import issue with the current version of Flask.
What are the plans to merge module-support into the main branch ? Do you envision further changes ?
from flask.
What are the plans to merge module-support into the main branch ? Do you envision further changes ?
Not sure yet, I'm thinking about how far I want to go with that. Still playing around.
from flask.
I did some more changes. Check out the module branch and build the docs and look at the api.rst for some ideas how that works.
from flask.
I think I will close that as wontfix. If anyone wants to play around with that idea, consider creating a snippet for it and we can then move it into core if it proves to be useful and flexible enough.
from flask.
Related Issues (20)
- GPU performance issues of flask framework
- Application Setup Tutorial doesn't work HOT 1
- Edit required in documentation: https://flask.palletsprojects.com/en/3.0.x/patterns/javascript/ #Replacing Content
- I'm seeing "GET /socket.io/?EIO=3&transport=polling&t=OozzqO3 HTTP/1.1" 404 errors running a simple flask app HOT 2
- Can I contribute HOT 6
- Improve error messages on simple after request hook bugs HOT 1
- Session data is not untagged properly when using other JSON providers
- jinja_loader type bug
- Flask 3.0.1 breaks path-separated command line arguments HOT 2
- Invalid `SERVER_NAME` + `url_for` leads to `AttributeError` HOT 3
- Issue matching route with methods=['OPTIONS'] when similar route appears later using ['GET', 'POST'] HOT 3
- use ThreadPoolExecutor and copy_current_request_context in flask will appear some bug
- `FileStorage` closed unexpectedly when using `copy_current_request_context` HOT 1
- Blueprint Dynamic URL For `string` vs. `path`
- Extend Config type HOT 1
- send_file doesn't work with objects HOT 1
- Add domain support to Blueprint HOT 5
- CHIPS support HOT 1
- The dependency specifiers are too relaxed HOT 3
- Route Aliases HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask.