6
我剛剛開始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
我不知道我在做什麼(錯):)
任何人有任何想法如何這可以/應該完成?
謝謝!
啊啊啊好吧,疑難雜症。現在工作:)感謝Rohan! – Jarrett