I'm trying to make an app similar to twitter where people can say what they want. how can i make entries appear in real time when a new post is added to mongodb.
I'm using flask and mongodb to make this web app. Here the route code which takes post content adds to database and returns the updated feed.
@app.route('/stories',methods=["POST",'GET'])
def stories():
username = session['username']
if request.method == 'POST':
content = request.form['message']
post = Post(username=username,content=content)
Database.insert('feed',post.json())
return render_template('story.html',username=username,posts = Database.find(collection='feed',data={}))
However this only works only when the page is refreshed manually. how can be this done in real time?
Aucun commentaire:
Enregistrer un commentaire