我在试着让猎鹰在网络上运行。我并不是一个网络专家,所以我很难了解这些应用程序是如何被服务的。
我的网络应用程序被设置为mod_wsgi 4.5.3/Python 2.7
据我所知,Falcon将在任何WSGI服务器上运行。当我吞下我的mod_wsgi服务器时,它是否自动配置为像Falcon这样的东西来运行?还是我还需要安装类似Gunicorn的东西?
当我设置我的set应用程序时,我收到了这样的目录结构:
app/htdocs/index.py在index.py文件中,我将在猎鹰教程中找到一个例子
import falcon
class ThingsResource(object):
def on_get(self, req, resp):
"""Handles GET requests"""
resp.status = falcon.HTTP_200
resp.body = 'Hello world!'
# falcon.API instances are callable WSGI apps
wsgi_app = api = falcon.API()
# Resources are represented by long-lived class instances
things = ThingsResource()
# things will handle all requests to the '/things' URL path
api.add_route('/things', things)我知道还有关于运行WSGI的说明,但这正是我感到困惑的地方-- way服务器是否已经在运行WSGI,还是我仍然需要类似Gunicorn之类的东西?如果需要,那么配置的最佳方式是什么?我需要一个克隆人来继续运营Gunicorn吗?
谢谢!
更新:
我检查了错误日志并收到了一个关于没有一个名为"application“的变量的WSGI错误,
所以我改变了:
wsgi_app = api = falcon.API()至:
application = falcon.API()这清除了错误,但是现在当我访问mydomain.com/things时,我得到了一个404错误(未找到/不存在)。
所以,这让我回到我最初的问题,下一步是什么?似乎url没有被正确地路由,所以它很可能与httpd.conf文件或类似的东西有关--再次,这是我第一次尝试获得类似的设置。
发布于 2016-08-25 18:47:53
这是答案(至少在最初的问题上,我敢打赌我会在不久的将来在同一个项目上搞砸其他事情)。
本质上,我能够将教程代码放入index.py文件中,该文件是在设置应用程序时生成的&在域上挂载。因此,我的教程代码如下所示:
import falcon
class ThingsResource(object):
def on_get(self,req,resp):
resp.status = falcon.HTTP_200
resp.body = 'Hello World!'
api = application = falcon.API()
things = ThingsResource()
api.add_route('/things', things)由于我找不到很多信息来启动一个猎鹰应用程序的网站,我看了类似的应用程序如何运行在网站(在这个例子中的Flask)。话虽如此,我还是在酒瓶上找到了一个片段,展示了如何在网络上建立起来。我不确定这是否意味着我的整个应用程序将工作,但我确实知道猎鹰教程代码至少可以工作。本质上,我只需根据下面的说明编辑httpd.conf文件:烧瓶网
WSGIPythonPath /home/yourusername/webapps/yourapp/htdocs/
#If you do not specify the following directive the app *will* work but you will
#see index.py in the path of all URLs
WSGIScriptAlias / /home/yourusername/webapps/yourapp/htdocs/index.py
<Directory /home/yourusername/webapps/yourapp/htdocs/>
AddHandler wsgi-script .py
RewriteEngine on
RewriteBase /
WSGIScriptReloading On
</Directory>我希望这对任何有类似问题的人都有帮助。
https://stackoverflow.com/questions/39112656
复制相似问题