我试图让 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/
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
由于fast-stemmer的问题,我很难安装我想要的任何rubygem。我把我得到的错误放在下面。Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingfast-stemmer:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcreatingMakefilemake"DESTDIR="cleanmake"DESTDIR=
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我意识到这可能是一个非常基本的问题,但我现在已经花了几天时间回过头来解决这个问题,但出于某种原因,Google就是没有帮助我。(我认为部分问题在于我是一个初学者,我不知道该问什么......)我也看过O'Reilly的RubyCookbook和RailsAPI,但我仍然停留在这个问题上.我找到了一些关于多态关系的信息,但它似乎不是我需要的(尽管如果我错了请告诉我)。我正在尝试调整MichaelHartl'stutorial创建一个包含用户、文章和评论的博客应用程序(不使用脚手架)。我希望评论既属于用户又属于文章。我的主要问题是:我不知道如何将当前文章的ID放入评论Controller。
这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Pythonconditionalassignmentoperator对于这样一个简单的问题表示歉意,但是谷歌搜索||=并不是很有帮助;)Python中是否有与Ruby和Perl中的||=语句等效的语句?例如:foo="hey"foo||="what"#assignfooifit'sundefined#fooisstill"hey"bar||="yeah"#baris"yeah"另外,类似这样的东西的通用术语是什么?条件分配是我的第一个猜测,但Wikipediapage跟我想的不太一样。
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht