gpt4 book ai didi

python - Flask Windows Apache 问题

转载 作者:可可西里 更新时间:2023-11-01 11:08:46 25 4
gpt4 key购买 nike

我试图让 Flask 在 Windows 上运行 Apache,但我遇到了下面的错误消息。关于可能导致此问题的原因有什么想法吗?

错误信息:

mod_wsgi (pid=4380): Exception occurred processing WSGI script 'C:/I4/importicus/importicus.wsgi'.
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] Traceback (most recent call last):
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] File "C:\\Python26\\lib\\site-packages\\flask-0.9-py2.6.egg\\flask\\app.py", line 1701, in __call__
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] return self.wsgi_app(environ, start_response)
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] File "C:\\Python26\\lib\\site-packages\\flask-0.9-py2.6.egg\\flask\\app.py", line 1689, in wsgi_app
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] response = self.make_response(self.handle_exception(e))
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] File "C:\\Python26\\lib\\site-packages\\flask-0.9-py2.6.egg\\flask\\app.py", line 1687, in wsgi_app
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] response = self.full_dispatch_request()
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] File "C:\\Python26\\lib\\site-packages\\flask-0.9-py2.6.egg\\flask\\app.py", line 1360, in full_dispatch_request
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] rv = self.handle_user_exception(e)
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] File "C:\\Python26\\lib\\site-packages\\flask-0.9-py2.6.egg\\flask\\app.py", line 1358, in full_dispatch_request
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] rv = self.dispatch_request()
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] File "C:\\Python26\\lib\\site-packages\\flask-0.9-py2.6.egg\\flask\\app.py", line 1344, in dispatch_request
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] return self.view_functions[rule.endpoint](**req.view_args)
[Fri Nov 30 14:47:47 2012] [error] [client 192.168.100.109] TypeError: application() takes exactly 2 arguments (0 given)

我的 WSGI 文件如下所示:

import sys
sys.path.insert(0, "c:\i4\importicus")

from importicus import importicus_main as application
application.debug = True

我的申请文件如下所示:

from flask import Flask, render_template,jsonify, request
from werkzeug import secure_filename
import importicus_functions
import ast, os, sys
importicus_main = Flask(__name__)

UPLOAD_FOLDER = 'uploads'
TEMPLATE_FOLDER = 'templates'
importicus_main.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
importicus_main.config['TEMPLATE_FOLDER'] = TEMPLATE_FOLDER



@importicus_main.route('/')
def application(environ, start_response):
status = '200 OK'
output = "Hello World! INSIDE"
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]

最佳答案

主要问题是您正在尝试编写 WSGI,而不是 Flask。 (Flask 更简单。)

这就是你想要的:

@importicus_main.route('/')
def application():
return "Hello World! INSIDE"

Controller (如应用程序功能)不接受参数,除非您的 url 字符串中有参数。一个例子是:

# /blog/1 would be a valid URL here
@importicus_main.route('/blog/<int:post_id>')
def blog_post(post_id):
return "This would be blog post number %s" % post_id

如果您跳过了 Flask 教程,请查看它 - 非常棒。我还建议让您的应用程序与内置测试服务器一起运行。您可以稍后轻松移植到 mod_wsgi(或其他)。

关于python - Flask Windows Apache 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13638961/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com