Using Python like PHP in Apache/Windows

2024/11/16 5:35:49

I understand that I should use mod_wsgi to run Python, and I have been trying to get that set up, but I'm confused about it:

This is a sample configuration I found for web.py:

LoadModule wsgi_module modules/mod_wsgi.soWSGIScriptAlias /appname /var/www/webpy-app/code.py/Alias /appname/static /var/www/webpy-app/static/
AddType text/html .py<Directory /var/www/webpy-app/>Order deny,allowAllow from all
</Directory>

So... I understand I have to configure my web server to point to the python application? Isn't there a way to use it like PHP, where, when you request a .py file, Python interprets it? How can I get my web server to the very basic state, where I can upload a file containing print "Hello World", request it, and have it say "Hello World"?

Answer

Most similar to the PHP model is perhaps Python Server Pages, PSP.

mod_python has a PSP handler. The files you create look like this:

<html>
<body>
<%
for n in range(3):# This indent will persist
%>
<p>This paragraph will be 
repeated 3 times.</p>
<%
# This line will cause the block to end
%>
This line will only be shown once.
</body>
</html>

Spyce takes the PSP model a step further, as does Webware for Python.

This article is a good introduction to mod_python's PSP.

https://en.xdnf.cn/q/71382.html

Related Q&A

django-oauth-toolkit : Customize authenticate response

I am new to Django OAuth Toolkit. I want to customize the authenticate response.My authenticate url configuration on django application is : url(authenticate/,include(oauth2_provider.urls, namespace=oa…

Pushing local branch to remote branch

I created new repository in my Github repository.Using the gitpython library Im able to get this repository. Then I create new branch, add new file, commit and try to push to the new branch.Please chec…

Does Pandas, SciPy, or NumPy provide a cumulative standard deviation function?

I have a Pandas series. I need to get sigma_i, which is the standard deviation of a series up to index i. Is there an existing function which efficiently calculates that? I noticed that there are the …

Python: compile into an Unix commandline app

I am not sure if I searched for the wrong terms, but I could not find much on this subject. I am on osx and Id like to compile a commandline python script into a small commandline app, that I can put i…

ModuleNotFoundError in PySpark Worker on rdd.collect()

I am running an Apache Spark program in python, and I am getting an error that I cant understand and cant begin to debug. I have a driver program that defines a function called hound in a file called h…

Sphinx is not able to import anything

I am trying to use sphinx to document a project of mine. I have used autodoc strings within all of my modules and files. I used sphinx-apidoc to automatically generate rst files for my code. So far, so…

Python : why a method from super class not seen?

i am trying to implement my own version of a DailyLogFile from twisted.python.logfile import DailyLogFileclass NDailyLogFile(DailyLogFile):def __init__(self, name, directory, rotateAfterN = 1, defaultM…

Extract features from last hidden layer Pytorch Resnet18

I am implementing an image classifier using the Oxford Pet dataset with the pre-trained Resnet18 CNN. The dataset consists of 37 categories with ~200 images in each of them. Rather than using the final…

Python Graphs: Latex Math rendering of node labels

I am using the following code to create a pygraphviz graph. But is it possible to make it render latex math equations (see Figure 1)? If not, is there an alternative python library that plots similar…

Given general 3D plane equation

Lets say I have a 3D plane equation:ax+by+cz=dHow can I plot this in python matplotlib?I saw some examples using plot_surface, but it accepts x,y,z values as 2D array. I dont understand how can I conv…