我刚刚开始Python web开发,并且选择了Bottle作为我选择的框架。
我正在尝试一个模块化的项目结构,因为我可以有一个“核心”应用程序,它有围绕它构建的模块,这些模块可以在安装过程中启用/禁用(或者在运行时,如果possible...not确定我将如何设置)。
我的“main”类如下:
from bottle import Bottle, route, run
from bottle import error
from bottle import jinja2_view as view
from core import core
app = Bottle()
app.mount('/demo', core)
#@app.route('/')
@route('/hello/<name>')
@view('hello_template')
def greet(name='Stranger'):
return dict(name=name)
@error(404)
def error404(error):
return 'Nothing here, sorry'
run(app, host='localhost', port=5000)我的“子项目”(即模块)是这样的:
from bottle import Bottle, route, run
from bottle import error
from bottle import jinja2_view as view
app = Bottle()
@app.route('/demo')
@view('demographic')
def greet(name='None', yob='None'):
return dict(name=name, yob=yob)
@error(404)
def error404(error):
return 'Nothing here, sorry'当我在浏览器中打开http://localhost:5000/demo时,它显示了一个500错误。瓶子服务器的输出是:
localhost - - [24/Jun/2012 15:51:27] "GET / HTTP/1.1" 404 720
localhost - - [24/Jun/2012 15:51:27] "GET /favicon.ico HTTP/1.1" 404 742
localhost - - [24/Jun/2012 15:51:27] "GET /favicon.ico HTTP/1.1" 404 742
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/bottle-0.10.9-py2.7.egg/bottle.py", line 737, in _handle
return route.call(**args)
File "/usr/local/lib/python2.7/dist-packages/bottle-0.10.9-py2.7.egg/bottle.py", line 582, in mountpoint
rs.body = itertools.chain(rs.body, app(request.environ, start_response))
TypeError: 'module' object is not callable文件夹结构为:
index.py
views (folder)
|-->hello_template.tpl
core (folder)
|-->core.py
|-->__init__.py
|-->views (folder)
|--|-->demographic.tpl我不知道我在做什么(错误的) :)
有谁知道该怎么做/应该怎么做?
谢谢!
发布于 2012-06-25 10:12:03
您正在将模块"core“传递给mount()函数。相反,您必须将瓶子应用程序对象传递给mount()函数,因此调用将如下所示。
app.mount("/demo",core.app)以下是mount()函数的正式文档。
装载(前缀、应用程序、**选项)源
将应用程序(瓶装或普通WSGI)挂载到特定的URL前缀。
示例:
admin(‘/admin/’,admin_app)
参数:
前缀-路径前缀或装载点。如果以斜杠结尾,则该斜杠是强制的。
WSGI应用程序-瓶子或应用程序的实例
https://stackoverflow.com/questions/11180806
复制相似问题