Vote count: 0
I have the following code to run a Flask server:
import os
from flask import Flask, url_for, request, render_template, redirect, flash, session
from bokeh.embed import autoload_server
from bokeh.client import pull_session
app = Flask(__name__)
@app.route('/login', methods = ['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if valid_login(request.form['username'], request.form['password']):
flash("Succesfully logged in")
session['username'] = request.form.get('username')
return redirect(url_for('welcome'))
else:
error = 'Incorrect username and password'
return render_template('login.html', error = error)
@app.route('/logout')
def logout():
session.pop('username', None)
return redirect(url_for('login'))
def valid_login(username, password):
if username == password:
return True
else:
return False
@app.route('/')
def welcome():
if 'username' in session:
return render_template('welcome.html', username = session['username'])
else:
return redirect(url_for('login'))
@app.route('/Gapminder')
def gapminder():
if 'username' in session:
sessione = pull_session(app_path = "/main")
bokeh_script = autoload_server(None, app_path = "/main", session_id=sessione.id)
return render_template("gapminder.html", bokeh_script = bokeh_script)
else:
return redirect(url_for('login'))
if __name__ == '__main__':
host = os.getenv('IP', 'locahost')
port = int(os.getenv('PORT', 5000))
app.debug = True
app.secret_key = '\xc9ixnRb\xe40\xd4\xa5\x7f\x03\xd0y6\x01\x1f\x96\xeao+\x8a\x9f\xe4'
app.run(host = host, port = port)
I run the bokeh server chart with
bokeh serve main.py --allow-websocket-origin=localhost:5000 --host *
and the flask server with
python run_flask.py
Well, I can see the bokeh reder in my local enviroment at the address
localhost:5006/main
and also the flask web page with the bokeh chart, also rendered and working ok at localhost:5000
The problem is when I try to access fro another machine in the same local network. I can see the bokeh render chart at ip:5006/main. The flask web page ip:5000 is also ok except the bokeh renderer, I can't see it.
can you help me please? Thanks a lot.
asked 15 secs ago
Flask server doesn't render bokeh charts in remote
Aucun commentaire:
Enregistrer un commentaire