Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Client OS username
#1
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 !?
Reply
#2
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.
Reply
#3
in python

import getpass 
username = getpass. getuser() 
print(username)
Reply
#4
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..
Reply
#5
(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())
Reply
#6
@Malt, OP is asking about getting username logged in on the client OS, not the server-side
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,533 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Hiding username and password on sql tantony 10 2,767 Oct-21-2022, 07:58 PM
Last Post: wavic
  Pulling username from Tuple pajd 21 3,226 Oct-07-2022, 01:33 PM
Last Post: pajd
  Trying to create a conditional with a username Realen 2 1,771 Jun-20-2020, 12:44 AM
Last Post: Realen
  creating a username and pword program using a #def statement and #dictionary zcode12 3 3,096 Oct-14-2018, 04:41 AM
Last Post: volcano63

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020