Comments (23)
@alexwaters It depends on your needs. Storing them in memory, a file or a database should all work.
from flask-socketio-chat.
You can choose to merge the chat functionality into your application, or keep it separate.
If you merge it, then you will have a chat route that serves the chat template that contains the client-side javascript for the page.
If you keep it separate, you need to run the application and the chat separately (on separate ports), and the application will have to be configured to know what URL to use to embed the chat.
from flask-socketio-chat.
Thanks, is it a lot of work for both options? Or better and easier to maintain separate apps and do a lot of importing? Not sure where to start in terms of the configuration needed.
from flask-socketio-chat.
I would combine everything in a single application. Just put the chat portion under a /chat
route, so that it does not collide with the application routes.
from flask-socketio-chat.
Alternatively merging your Flask-SocketIO-Chat as one of the tabs in your microblog? So after login and authenticated, 'Chat' will be next to the Logout or other available tabs.
from flask-socketio-chat.
- Refactored package names in Flask-SocketIO-Chat to chat-app
- Refactored package names in microblog to main-app before copying all folders from Flask-SocketIO-Chat into microblog to avoid package name clashes.
- Then changed run.py in microblog:
from gevent import monkey
monkey.patch_all()
from app_main import create_app, socketio
app = create_app(True)
# app.run(debug=True)
if __name__ == '__main__':
socketio.run(app)
and now the microblog/app_main/ __init__.py:
def create_app(debug=False):
global app, db, lm, oid, mail, babel
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'
lm.login_message = lazy_gettext('Please log in to access this page.')
oid = OpenID(app, os.path.join(basedir, 'tmp'))
mail = Mail(app)
babel = Babel(app)
app.debug = debug
app.config['SECRET_KEY'] = 'gjr39dkjn344_!67#'
from app_chat.main import main as main_blueprint
app.register_blueprint(main_blueprint)
socketio.init_app(app)
return app
But app is still not global? Because I get:
app.json_encoder = CustomJSONEncoder
NameError: global name 'app' is not defined
Could this be related this this question:
http://stackoverflow.com/questions/21028254/nameerror-name-app-is-not-defined-with-flask
from flask-socketio-chat.
I don't see where you have the reference to app.json_encoder
, so I can't really tell you what the problem is.
Also the global app
is suspicious. If you are using the app factory pattern then you do not need to make app
a global variable.
from flask-socketio-chat.
In microblog(app - > app_main)-> __init__.py
, but does defining global app inside create_app already makes it global?
def create_app(debug=False):
global app, db, lm, oid, mail, babel
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'
lm.login_message = lazy_gettext('Please log in to access this page.')
oid = OpenID(app, os.path.join(basedir, 'tmp'))
mail = Mail(app)
babel = Babel(app)
app.debug = debug
app.config['SECRET_KEY'] = 'gjr39dkjn344_!67#'
from app_chat.main import main as main_blueprint
app.register_blueprint(main_blueprint)
socketio.init_app(app)
return app
class CustomJSONEncoder(JSONEncoder):
"""This class adds support for lazy translation texts to Flask's
JSON encoder. This is necessary when flashing translated texts."""
def default(self, obj):
from speaklater import is_lazy_string
if is_lazy_string(obj):
try:
return unicode(obj) # python 2
except NameError:
return str(obj) # python 3
return super(CustomJSONEncoder, self).default(obj)
app.json_encoder = CustomJSONEncoder
from flask-socketio-chat.
Yeah, okay. You can't access app
in the global scope if you are working with an app factory function. That needs to go in the factory function.
from flask-socketio-chat.
Sorry the factory function is located in?
from flask-socketio-chat.
Doesn't matter where you put the factory function. It can go in the __init__.py
file, or in a different module inside the application package.
It seems to me you are trying to convert microblog to use an app factory function, but you did not go all the way with the conversion. Any references to app
as a global variable need to go, there is no app
global when you structure your application in this form.
from flask-socketio-chat.
Sorry, I meant how do you make a factory function as opposed to the file location.
from flask-socketio-chat.
This repository has a factory function in this file, that should be a good example.
If you want to see one a bit more complex, the one in my Flasky repository is a good one to study.
from flask-socketio-chat.
Thanks I thought it was blueprint related.
from flask-socketio-chat.
I'm also looking to implement this under a larger web application. Any recommendations for storing a history of the messages?
from flask-socketio-chat.
hello Miguelgrinberg
from flask-socketio-chat.
How can i work with Flask socketio blueprints to pull data from Ibm watson
from flask-socketio-chat.
@KunleMichaels not sure what you are asking. What do you mean by "flask socketio blueprints"?
Presumably Watson has some API mechanism for clients to get data? I don't see what Flask-SocketIO has to do with it.
from flask-socketio-chat.
Thanks for the reply Miguel, I'm not so good with the terms but I will try to be as clear as possible
from flask-socketio-chat.
I'm building a bot that carries out financial services based on requests from users I'm working with IBM dashdb, how can I use a flask framework without sqlalchemy and sqlite. Since IBM dashdb doesn't support sqlalchemy
from flask-socketio-chat.
Flask does not require sqlalchemy, you can use any database that you like. For dashdb, you can use https://pypi.python.org/pypi/ibmdbpy.
from flask-socketio-chat.
Thanks a whole lot @miguelgrinberg
from flask-socketio-chat.
This issue will be automatically closed due to being inactive for more than six months. Seeing that I haven't responded to your last comment, it is quite possible that I have dropped the ball on this issue and I apologize about that. If that is the case, do not take the closing of the issue personally as it is an automated process doing it, just reopen it and I'll get back to you.
from flask-socketio-chat.
Related Issues (20)
- Trying to make a chatbot HOT 3
- Accessing to application context in a background task with Blueprints HOT 11
- Scaling with Redis HOT 1
- Server receives event correctly, but It doesn't execute method HOT 1
- Unicode message seems not work with SSL HOT 4
- Not working on Google chrome HOT 2
- Understanding the structure HOT 3
- Commands HOT 3
- Clean install virtualenv error HOT 2
- Making calls to external API with only 1 gunicorn worker HOT 12
- Flask-socketio nginx HOT 11
- socketio.run (app) vs app.run ()
- way to change the hosted socket HOT 2
- Add Password Support: HOT 1
- Flask-SocketIO-Chat with background event
- didn't work on localhost cuz of `https` missing from source HOT 4
- Socket Handlers not being Triggered Even after i've imported them HOT 13
- Example code with Auth key at the time of connect HOT 1
- python version HOT 2
- failed to install requirements on windows due to greenlet HOT 2
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-socketio-chat.