miguelgrinberg / Flask-SocketIO-Chat

A simple chat application that demonstrates how to structure a Flask-SocketIO application.
http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent
MIT License
676 stars 242 forks source link

Understanding the structure #20

Closed writeson closed 5 years ago

writeson commented 5 years ago

Hi Miguel,

I have a couple of questions about this example:

  1. In your code you don't have any lines like this: app.register_blueprint(...). I normally have this in my main entry point after I've gotten an 'app' instance. Is this unnecessary? I wanted to understand this better.
  2. I found this example code while trying to understand how to use Blueprint with websockets. Based on your code it looks like Blueprints (and any kind of 'url_prefix') aren't used with websockets, and any kind of 'url_prefix' should be handled with a socketio namespace parameter in the decorator. Is that correct?

Thanks in advance for your help! Doug

miguelgrinberg commented 5 years ago
  1. I do have register_blueprint() actually. It's in the application factory function: https://github.com/miguelgrinberg/Flask-SocketIO-Chat/blob/master/app/__init__.py#L14.
  2. Correct, blueprints are a Flask feature, nothing to do with Flask-SocketIO.
writeson commented 5 years ago

Thanks for the clarification, I don't know how I missed the register_blueprint in the create_app() function, sorry for D'OH moment on my part.

Also, thanks also for the clarification that Blueprints isn't used with Flask-SocketIO. Based on the structure of the app folders I was mistakenly looking for a connection there.

miguelgrinberg commented 5 years ago

No problem. I could see how this can be a bit confusing. Maybe I should have placed the events.py module outside of the main package so that it is more clear that it is not part of the blueprint. As things are, the main package contains both the blueprint and the Socket.IO stuff.