Coder Social home page Coder Social logo

Make endpoint optional in @route about flask HOT 10 CLOSED

pallets avatar pallets commented on April 26, 2024
Make endpoint optional in @route

from flask.

Comments (10)

mitsuhiko avatar mitsuhiko commented on April 26, 2024

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.

cgrinds avatar cgrinds commented on April 26, 2024

I like this - similar to what I was doing with my routes changes but much better.

from flask.

mitsuhiko avatar mitsuhiko commented on April 26, 2024

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.

cgrinds avatar cgrinds commented on April 26, 2024

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.

mitsuhiko avatar mitsuhiko commented on April 26, 2024

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.

cgrinds avatar cgrinds commented on April 26, 2024

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.

danjac avatar danjac commented on April 26, 2024

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.

mitsuhiko avatar mitsuhiko commented on April 26, 2024

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.

mitsuhiko avatar mitsuhiko commented on April 26, 2024

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.

mitsuhiko avatar mitsuhiko commented on April 26, 2024

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)

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.