1

我试图让 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]
4

1 回答 1

6

主要问题是您正在尝试编写 WSGI,而不是 Flask。(烧瓶更容易。)

这就是你想要的:

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

控制器(如应用程序函数)不带参数,除非您的 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(或其他)。

于 2012-11-30T06:52:16.717 回答