我刚刚开始 Python Web 开发,并选择了 Bottle 作为我选择的框架。
我正在尝试拥有一个模块化的项目结构,因为我可以拥有一个围绕它构建的模块的“核心”应用程序,这些模块可以在设置期间启用/禁用(或者在运行中,如果可能的话.. .不确定我将如何设置它)。
我的“主要”课程如下:
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
我不知道我在做什么(错误):)
任何人都知道如何/应该如何做到这一点?
谢谢!