Hi All,
I have a flask application, would like to fetch the OS username by default for creating a registration portal. I don’t want the users to provide username as Input.
Please let me know how can we grab this value !?
Firstly, why do you need this information?
Secondly, this isn't really a Python question. Remember that the Python code runs on the client and not the server. Client-side code is written in JavaScript (or something that can be transpiled to JS). Having said that, this is likely going to be difficult to do - browsers aren't going to allow you much access to the underlying OS as that would be quite a security risk, wouldn't it?
You could of course write a desktop app or another web app that runs on the machine and communicates with the server by means of an HTTP API.
in python
import getpass
username = getpass. getuser()
print(username)
Did you miss the part about this being a web app? The server side code isn't, in general, going to be running on the client machine..
(Sep-23-2019, 06:01 PM)ImPyBoy17 Wrote: [ -> ]Hi All,
I have a flask application, would like to fetch the OS username by default for creating a registration portal. I don’t want the users to provide username as Input.
Please let me know how can we grab this value !?
OS username, you mean? Login username?
If yes, we can grep them using
import os
print(os.getlogin())
@
Malt, OP is asking about getting username logged in on the client OS, not the server-side