我有一个用 python 编写的古老 web 应用程序。它基本上是一堆 .py 文件。例如:
display.py:
import cgi import re import string import operator from urllib.parse import urlparse from errors import herigean from routines import * error = false query = cgifieldstoragetodict(cgi.fieldstorage()) opening_index = 0 # flag to indicate whether we're opening the index page if ('what' not in query): query['what'] = 'index' if 'fs' not in query: query['fs'] = str(default_font_size) # open page to display try: fil = open('html/'+query['what']+'.fmt') textlines = fil.read() queryreg = re.compile('query:fs:query') textlines = queryreg.sub(query['fs'],textlines) fil.close() except ioerror: error = true if query['what'] == 'about': try: fil = open('legal/lgpl-3.0.txt') lgpl = fil.read() fil.close() fil = open('legal/gpl.txt') gpl = fil.read() fil.close() fil = open('html/availability.fmt') availability = fil.read() fil.close() except ioerror: error = true if query['what'] == 'corpus': try: fil = open('html/availability.fmt') [...] if error: herigean() else: print(frontmatter)
等等
如何使用虚拟环境中安装的 mod_wsgi 在 apache 代理后面运行它?现在我有一个pythong 3.11虚拟环境,其中安装了mod_wsgi-express 5。我可以使用以下命令成功运行test.py:
立即学习“Python免费学习笔记(深入)”;
mod_wsgi-express启动服务器测试.py
def application(environ, start_response): start_response('200 ok', [('content-type', 'text/html')]) return [b'hello, world!']
如何运行我的旧 python 应用程序?我是否只是将每个 .py 文件包装在 def application(environ, start_response): 中?任何帮助将不胜感激。
添加:
该应用程序的 www.index.html 。里面有一个 。这就是目前的服务方式。
附加ii
我无法获得输出:使用时
def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) [...] return print(frontmatter)
我在日志中获取了整个 html,然后是 typeerror: 'nonetype' object is not iterable 和浏览器上的内部服务器错误。
我应该使用 yield bytes(html) 而不是 print。
以上就是将旧的 Python Web 应用程序转变为 WSGI 就绪和 Apache的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号