Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
Running a python script with website input

I've got a bit of webdev experience, and just started learning python. I've created a python script that takes in an argument, and then runs a program, and prints print statements into the console. I'm curious if it's possible to put this program behind a webpage.

i.e. Webpage with a dropdown, chose the option and click a "Go" button. Then the python script is run with the option you chose, and your report is shown on the page.

I've looked at a few similar posts: Execute a python script on button click

run python script with html button

but they seem to offer very different solutions, and people seem to think the PhP idea is insecure. I'm also looking for something a bit more explicit. I'm fine to change the python script to return ajson or something instead of just print statements.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

A pretty common way to communicate between a webpage and a python program is to run the python as a WSGI server. Effectively the python program is a separate server which communicates with the webpage using GETs and POSTs.

One nice thing about this approach is that it decouples the Python app from the the web-page proper. You can test it by sending http requests directly to a test server while you're developing.

Python includes a built-in WSGI implementation, so creating a WSGI server is pretty simple. Here's a very minimal example:

from wsgiref.simple_server import make_server

# this will return a text response
def hello_world_app(environ, start_response):
    status = '200 OK'  # HTTP Status
    headers = [('Content-type', 'text/plain')]  # HTTP Headers
    start_response(status, headers)
    return ["Hello World"]

# first argument passed to the function
# is a dictionary containing CGI-style environment variables 
# second argument is a function to call
# make a server and turn it on port 8000
httpd = make_server('', 8000, hello_world_app)
httpd.serve_forever()
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!