-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should Flask-Classy honor url_prefix where registering Blueprints? #13
Comments
In my opinion, it totally should. I need to get this turned into a failing test case so I can get a fix worked out. |
Awesome! Would love to see this added. |
Here's a test case for you: https://gist.github.com/4552573 diff --git a/test_classy/test_blueprints.py b/test_classy/test_blueprints.py
index 6ea0284..71f079c 100644
--- a/test_classy/test_blueprints.py
+++ b/test_classy/test_blueprints.py
@@ -65,8 +65,10 @@ def test_bp_custom_http_method():
resp = client.post("/basic/route3/")
eq_("Custom HTTP Method", resp.data)
+def test_bp_url_prefix():
+ foo = Blueprint('foo', __name__)
+ BasicView.register(foo)
+ app.register_blueprint(foo, url_prefix='/foo')
-
-
-
-
+ resp = client.get('/foo/')
+ eq_('Index', resp.data) |
Looks like it does work actually. I think you forgot that def test_bp_url_prefix():
foo = Blueprint('foo', __name__)
BasicView.register(foo, route_base="/")
app.register_blueprint(foo, url_prefix='/foo')
resp = client.get('/foo/')
eq_('Index', resp.data) |
Right, and this is how we're working around this issue but I don't think that you should require setting a |
Ahhhh I think I understand now. So what you're saying is that when you set a
It's consistent and works the same wether you use a Aside from that though, I think that using the
I think it might make more sense to make the default |
What I'm saying is that Flask's API shouldn't be trumped by Flask-Classy. In other words if I pass in I think the fundamental problem here is Flask-Classy is changing the behavior of Flask Blueprints in a non-obvious and surprising way. But I don't think the intention is to break the Flask API. In my view, as it is currently, Flask-Classy is breaking the Flask API (in fact you can see this by my unit test which should pass if the Blueprint API weren't being overloaded later on by Flask-Classy's automatic routing behavior). The reason this is important is because Perhaps one possibility might simply be to not automatically route to a base other than '/', so that the API becomes explicit instead of implicit, which seems to be the source of the problems here. Now it might not be practical to change the current behavior on |
Flask-Classy doesn't change the behavior of Flask or Blueprints at all (take a look at the code, seriously no modification is made to Flask or Blueprints). I think you may be misunderstanding that all Assume you have this view: class BasicView(FlaskView):
def my_method(self):
return "Hello" If you register this view with a Flask app directly like
You'll the route to
If you take that exact same view and register it with a bp = Blueprint()
BasicView.register(bp)
app.register_blueprint(bp, url_prefix="/my_bp") Then the route to that same
What you're asking is that when you specify a class AwesomeView(FlaskView):
def my_method(self):
return "Woah! Awesome!"
class RadicalView(FlaskView):
def my_method(self):
return "Totally rad." Both of these views have a view method called bp = Blueprint()
AwesomeView.register(bp)
RadicalView.register(bp)
app.register_blueprint(bp, url_prefix='/my_bp') What would you expect to happen if I then visited
Which view wins in this case, should it be That's why |
I think the best solution for the OP is what I did:
And inherit from that. Don't inherit from it if you want the default behavior from FlaskView, or if you're going to use multiple FlaskView classes on a single blueprint. Yes, I know this is old, but it seemed like it needed an answer. :) |
I'm not entirely sure if this by design, but it seems as though the register method of FlaskView does not honor url_prefix as defined by calls to the register_blueprint method.
e.g. should something like this work?
Basically I would expect to now be able to navigate to http://localhost:5000/bp/ and see the "foobar" response. However this doesn't seem to be the case.
The text was updated successfully, but these errors were encountered: