简体   繁体   English

从浏览器运行python程序

[英]Run a python program from browser

I want to run a python program (kinda like this) from a browser 我想从浏览器运行python程序(像这样)

Anyway, as you see it has a few inputs, and i would like to "translate" that into a kind of form 无论如何,如您所见,它有一些输入,我想将其“翻译”成一种形式

def addNew():
     appendBase = open('dBase.cfg','a')
     uname = input('Username: ')
     pword = input('Password: ')
     appendBase.write(uname+','+pword+'\n')
     print('\nAdded new profile: \n'+uname+','+pword)
     appendBase.close()

Also i dont know how to get the print to the page, so it can show it 我也不知道如何将打印内容打印到页面上,所以它可以显示它

I've just started learning, so go easy on me, please 我刚刚开始学习,所以请放轻松

It is not possible to actually run this in the browser, for various reasons. 由于各种原因,不可能在浏览器中实际运行它。

  1. you can't run python in browsers. 您无法在浏览器中运行python。 only javascript 只有JavaScript
  2. you can't open local files from a browser 您无法通过浏览器open本地文件
  3. there's no command line to input from some terminal 没有命令行可以从某些终端input

Most things you see on the web have two parts 您在网络上看到的大多数内容都有两个部分

  • a part that actually runs in the browser. 实际上在浏览器中运行的部分。 Written in HTML and javascript 用HTML和javascript编写
  • another part where the browser connects, to send and receive data. 浏览器连接的另一部分,用于发送和接收数据。 That can be done in any language, including python. 可以使用任何语言(包括python)来完成。 However, that part is not visible in the browser 但是,该部分在浏览器中不可见

The two parts communicate using HTTP protocol. 这两个部分使用HTTP协议进行通信。 So, start by reading a bit on HTML/javascript ( W3Schools is an easy way to get started). 因此,从阅读HTML / javascript开始( W3Schools是入门的简便方法)。 When you feel comfortable with that, practice with a python web framework ( django is the most popular, but flask is the easiest to get started), and see how javascript uses HTTP to connect to that. 当您对此感到满意时,请尝试使用python网络框架进行练习( django是最受欢迎的,但最容易入门的是flask ),并查看javascript如何使用HTTP连接到该框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM