Skip to content
Advertisement

How can I run a Python script in HTML?

Currently I have some Python files which connect to an SQLite database for user inputs and then perform some calculations which set the output of the program. I’m new to Python web programming and I want to know: What is the best method to use Python on the web?

Example: I want to run my Python files when the user clicks a button on the web page. Is it possible?

I started with Django. But it needs some time for the learning. And I also saw something called CGI scripts. Which option should I use?

Advertisement

Answer

It probably would depend on what you want to do. I personally use CGI and it might be simpler if your inputs from the web page are simple, and it takes less time to learn. Here are some resources for it:

However, you may still have to do some configuring to allow it to run the program instead of displaying it.

Here’s a tutorial on that: Apache Tutorial: Dynamic Content with CGI

Advertisement