The web page should display data (PC name, domain, login and some others) the PC on which it is open. For me, it displays data even on remote PCs on the network, the PC on which the python Flask script is running. Is this really how it should be, or am I doing something wrong? If possible, a link or a detailed description.
import json
import os
import socket
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template("index.html")
@app.route('/get_values')
def get_values():
login = os.getlogin()
hostname = socket.gethostname()
local_ip = socket.gethostbyname(hostname)
result = {f'"login": "{login}", "hostname": "{hostname}", "ip": "{local_ip}"'}
result = str(result).replace("'", "")
result = json.loads(result)
return result
if __name__ == '__main__':
app.run(host="0.0.0.0", port="5000")
There is a template index.html to which js adds values, but no matter on which PC the site is opened, the data is always from the local PC running the flask server.
$.get('/get_values',
function(data)
{
$("#login").val(data.login);
$("#hostname").val(data.hostname);
$("#ip").val(data.ip);
});
I use PyCharm to work with python
I need to achieve a result when the web application allows me to work with the local computer on which it is running in the same way as if it were a desktop application.
Владислав К. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.