Comments (5)
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.
@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.
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.
Hrm yep, not sure how I didn't run into that before... anyway, fix pushed to master
from flask-unchained.
Works now, thank you for that.
from flask-unchained.
Related Issues (11)
- KeyError: 'No serializer found for the User model HOT 5
- wrong redirect uri for oauth using docker HOT 2
- immutabledict is not defined when using SQLAlchemy Bundle & Migrations HOT 1
- Possible switch from venv to pipenv HOT 3
- Where would you put plain python classes? HOT 1
- [BUG] Admin bundle points to security.login, but Security bundle defines security_controller.login HOT 3
- KeyError: 'UserResource.patch' HOT 2
- no such table: flask_sessions HOT 2
- Create a new release? HOT 1
- consider using black formatter
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-unchained.