English 中文(简体)
使用粘贴部署一个 Flask 应用程序
原标题:Deploying a Flask application using Paste

我用弗拉斯克(Flask)建立一个网络服务,我正试图用Paster(Paster)来部署一个简单的“哈罗,世界”应用程序。我很难把一切都配置到一起工作。我看过Google关于使用虚拟和Zcbuilt(Vievenv)和Zcbuildout(Zcbuilt)用粘贴器用粘贴器运行弗拉斯克的网络服务,但对于一个非常基本的应用程序来说,这似乎有点过份。现在,当我试图用我的应用程序加载一个 URL(URL) 时,我得到这个错误:

Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/paste/httpserver.py", line 1068, in process_request_in_thread
  self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
  self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 639, in __init__
  self.handle()
File "/usr/lib/python2.7/dist-packages/paste/httpserver.py", line 442, in handle
  BaseHTTPRequestHandler.handle(self)
File "/usr/lib/python2.7/BaseHTTPServer.py", line 343, in handle
  self.handle_one_request()
File "/usr/lib/python2.7/dist-packages/paste/httpserver.py", line 437, in handle_one_request
  self.wsgi_execute()
File "/usr/lib/python2.7/dist-packages/paste/httpserver.py", line 287, in wsgi_execute
  self.wsgi_start_response)
AttributeError: GraffitiApp instance has no __call__ method

我的应用程序配置看起来像 :

[DEFAULT]
loglevel = WARN
browser_cache_ttl = 30

[app:main]
use = egg:GraffitiService

[server:main]
use = egg:Paste#http
host = 0.0.0.0
port = %(graffiti_port)s

我的应用程序代码看起来像:

from flask import Flask

app = Flask(__name__)
app.debug = True

class GraffitiApp:

    @app.route( / )
    def hello_world():
        return "Hello World!"

    @app.route( /other )
    def other_page():
        return "Other page!"

    def main():
        app.run(debug = True)

if __name__ == "__main__":
    app.run(debug = True)

我是否需要创建 方法, 并绘制任何 URL 传送到相应函数的地图, 还是需要更改我的配置?

<强 > EDIT

我使用一家工厂, 名为主. Py, 因为错误,

import logging

from graffiti import GraffitiApp

def make_app(globalArgs, **localArgs):
    loglevelname = globalArgs.get("loglevel", "INFO").lower()

    if loglevelname ==  critical :
        loglevel = logging.CRITICAL
    elif loglevelname ==  debug :
        loglevel = logging.DEBUG
    elif loglevelname ==  error :
        loglevel = logging.ERROR
    elif loglevelname ==  fatal :
        loglevel = logging.FATAL
    elif loglevelname ==  info :
        loglevel = logging.INFO
    elif loglevelname ==  warn  or loglevelname ==  warning :
        loglevel = logging.WARN
    else:
        loglevel = logging.NOTSET
        loglevelname =  notset 

    FORMAT = "%(asctime)s %(name)s %(levelname)s %(message)s"
    logging.basicConfig(format = FORMAT, level = loglevel)
    logging.info("Log level set to %s" % (loglevelname.upper()))

    return GraffitiApp()
最佳回答

看起来服务器正在尝试运行您的 GraffitiApp () clask () example app 类, 当它应该运行 Flask () exience app 时 。

问题回答

弗特普(抱歉,但你的密码让我目不转睛):

import logging

from graffiti import GraffitiApp

def make_app(globalArgs, **localArgs):
    loglevelname = globalArgs.get("loglevel", "INFO")
    loglevel = getattr(logging, loglevelname.upper(), logging.NOTSET)


    FORMAT = "%(asctime)s %(name)s %(levelname)s %(message)s"
    logging.basicConfig(format = FORMAT, level = loglevel)
    logging.info("Log level set to %s" % (loglevelname))

    return GraffitiApp()




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签