首页 > 解决方案 > 如何在apache中指定python文件的路径

问题描述

我现在正在 windows10 上构建服务器。
使用的服务器是apache,语言是python。
修改 apache 的 httpd.conf 以使用 python 文件。
我在 htdocs 下创建了一个名为 helloworld.py 的 python 文件。
该文件的内容如下。

#!C:\Users\z05974ac\AppData\Local\Microsoft\WindowsApps\python.exe
# coding:utf-8
print ("Content-Type: text/html\n");
print ("Hello World!");

第一行是输入 where python 的结果。
但是,显示了以下错误消息。

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at admin@example.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

我认为设置路径的方式存在问题。
但我不明白原因。
我会很感激你的教导。
谢谢你。

标签: pythonapachepath

解决方案


我对 Apache 了解不多,但是否因为您在行尾有一个分号?Python 只需要一个新行来分隔代码,所有 C 语言都需要一个分号在它们的末尾。只需将这些行重写为:

print ("Content-Type: text/html\n")
print ("Hello World!")

推荐阅读