Reputation: 1221
I'm reading the documentation and have implemented a working Flask-SSE application. Documentation referenced here: https://flask-sse.readthedocs.io/en/latest/quickstart.html
It notes to set up a route for "sse.stream" and "/stream".
Is that hard-coded within the library, or is there a way to change that to "/api" for example? I did attempt to simply change them, but received error "Could not build url for endpoint 'see.api' with values blah. Did you mean 'sse.stream' instead?"
Found this on the documentation as well: https://flask-sse.readthedocs.io/en/latest/advanced.html
Looks like they did exactly what I tried, changing it to '/sse', but when I change mine to '/api', mine errors out.
Adding the code line I'm attempting to use:
app.register_blueprint(sse, url_prefix='/api')
Upvotes: 0
Views: 102
Reputation: 1221
Got a response directly from David, the developer of the Flask-SSE library.
Here is how you are able to use any url you want:
from flask_sse import sse, ServerSentEventsBlueprint
sse = ServerSentEventsBlueprint('sse', 'sse')
sse.add_url_rule(rule="", endpoint="api", view_func=sse.stream)
app.register_blueprint(sse, url_prefix='/api')
Here I am changing the default "/stream" to "/api" and registering it as my blueprint.
Now, I'm able to use "{{ url_for(sse.api) }}" on my front-end in jinja.
Thanks again David!
Upvotes: 0