GithubHelp home page GithubHelp logo

Comments (5)

briancappello avatar briancappello commented on August 10, 2024

This should work, as long as you give each route a unique endpoint name.

Reading more about this, in the upstream docs it suggests what you're doing should be working. Personally, that syntax not only looks awful but is also quite un-intuitive. I would much rather have end-user code be able to write this:

@route('/whatever/<string:param>/', defaults=dict(param='value'))

And then behind the scenes, we do what needs to be done for it to work with Werkzeug (namely, registering two routes with Flask). I think that code should end up living in RegisterRoutesHook.process_objects, if you want to play around with it (See the hooks module of the controller bundle). I'm happy to take a stab at it later too, this is getting a bit deep into the weeds of the implementation.

from flask-unchained.

briancappello avatar briancappello commented on August 10, 2024

@chriamue I just pushed a fix to master that hopefully implements support for multiple routes with the same endpoint name on view functions/methods. Can you give it a shot? I didn't add any magic (yet) so for now, you need to continue using the multiple routes (one with default parameter, the other with the parameter as part of the url rule)

from flask-unchained.

chriamue avatar chriamue commented on August 10, 2024

Hi thank you for your quick reply.

It seems I'm getting an assertion error now.

@route('/list/<string:project>', defaults=dict(req_path=''))
    @route('/list/<string:project>/<path:req_path>')
    def listing(self, project, req_path):
...
backend_1_2b698f4c7894 | Traceback (most recent call last):
backend_1_2b698f4c7894 |   File "/flask/src/src/flask-unchained/flask_unchained/cli.py", line 56, in cli_create_app
backend_1_2b698f4c7894 |     return AppFactory.create_app(env)
backend_1_2b698f4c7894 |   File "/flask/src/src/flask-unchained/flask_unchained/app_factory.py", line 75, in create_app
backend_1_2b698f4c7894 |     unchained.init_app(app, env, bundles, _config_overrides=_config_overrides)
backend_1_2b698f4c7894 |   File "/flask/src/src/flask-unchained/flask_unchained/unchained.py", line 107, in init_app
backend_1_2b698f4c7894 |     run_hooks_hook.run_hook(app, bundles, _config_overrides=_config_overrides)
backend_1_2b698f4c7894 |   File "/flask/src/src/flask-unchained/flask_unchained/hooks/run_hooks_hook.py", line 34, in run_hook
backend_1_2b698f4c7894 |     hook.run_hook(app, bundles)
backend_1_2b698f4c7894 |   File "/flask/src/src/flask-unchained/flask_unchained/bundles/controller/hooks/register_routes_hook.py", line 27, in run_hook
backend_1_2b698f4c7894 |     self.process_objects(app, routes)
backend_1_2b698f4c7894 |   File "/flask/src/src/flask-unchained/flask_unchained/bundles/controller/hooks/register_routes_hook.py", line 70, in process_objects
backend_1_2b698f4c7894 |     **route.rule_options)
backend_1_2b698f4c7894 |   File "/flask/src/src/flask-unchained/flask_unchained/flask_unchained.py", line 71, in add_url_rule
backend_1_2b698f4c7894 |     provide_automatic_options, **options)
backend_1_2b698f4c7894 |   File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 66, in wrapper_func
backend_1_2b698f4c7894 |     return f(self, *args, **kwargs)
backend_1_2b698f4c7894 |   File "/usr/local/lib/python3.7/site-packages/flask/app.py", line 1221, in add_url_rule
backend_1_2b698f4c7894 |     'existing endpoint function: %s' % endpoint)
backend_1_2b698f4c7894 | AssertionError: View function mapping is overwriting an existing endpoint function: file_controller.listing

from flask-unchained.

briancappello avatar briancappello commented on August 10, 2024

Hrm yep, not sure how I didn't run into that before... anyway, fix pushed to master

from flask-unchained.

chriamue avatar chriamue commented on August 10, 2024

Works now, thank you for that.

from flask-unchained.

Related Issues (11)

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.