3

How can I execute a Python script on a webpage?

I've used XAMPP to create the Apache server. Are there any tutorials/examples or guides on how to execute a .py script? I'm using Windows 7 and have installed Python on my local machine. If I access the .py script via the web link, it looks as if its HTML code and nothing is executed.

2
  • you can use mod_python modpython.org Commented Aug 12, 2012 at 20:12
  • 1
    modpython has stopped development long time ago and is not supported with recent versions of python Commented Aug 12, 2012 at 20:57

3 Answers 3

2

Typically, you don't execute Python in the browser. Instead, the browser accesses a resource (or "webpage", like http://example.com/mypage) by requesting the resource from the server. The server (for example, Apache), when administered correctly, passes off handling of the request to some Python script. Then, your Python script creates some output (for example, HTML) which the server then returns to the browser for the browser to display.

However, some web sites have found it useful to have logic (scripts) run in the browser, rather than on the server. The standard way of doing this is using JavaScript (although in the past there WERE other languages built into browsers, such as VBScript in Internet Explorer).

Right now, pretty much all browsers have settled on JavaScript as THE scripting language in the browser. In order for you to use any other language in the browser (including Python), the browser must support that scripting language (or needs to have an add-on to support that scripting language). Simply having Python installed on your client alongside the browser is not enough. For more information, please see the Python documentation Web Browser Programming.

Another option is to use something like Pyjs. This is a library that has you write your code in Python, and converts the necessary parts to JavaScript. This isn't exactly "Python in the browser", but it might be something you are looking for.

Sign up to request clarification or add additional context in comments.

Comments

0

I guess this links will help.... https://community.apachefriends.org/f/viewtopic.php?t=42975

Comments

-1

Usually a good resource for Python is the official documentation.

They do a great job of explaining many aspects of Python. Using Python on the web is a big part and they have a great overview.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.