0
我試圖讓web.py上運行一個簡單的博客,它啓動罰款(python bin/blog.py),但是當我輸入網站它說它無法找到模板。我很確定這條道路是正確的,我在此之前做了一個簡單的待辦事項清單,它工作正常。怎麼了?沒有模板命名索引
,這裏是我的項目文件夾的樣子:
-blogpy/
-bin/
-blogwebpy/
-docs/
-templates/
-tests/
下面是blog.py它位於倉代碼(模板位於模板):
import web
import model
### Url mappings
urls = (
'/', 'Index',
'/view/(\d+)', 'View',
'/new', 'New',
'/delete/(\d+)', 'Delete',
'/edit/(\d+)', 'Edit',
)
### Templates
t_globals = {
'datestr': web.datestr
}
render = web.template.render('templates/', base='base', globals=t_globals)
class Index:
def GET(self):
""" Show page """
posts = model.get_posts()
return render.index(posts)
class View:
def GET(self, id):
""" View single post """
post = model.get_post(int(id))
return render.view(post)
class New:
form = web.form.Form(
web.form.Textbox('title', web.form.notnull,
size=30,
description="Post title:"),
web.form.Textarea('content', web.form.notnull,
rows=30, cols=80,
description="Post content:"),
web.form.Button('Post entry'),
)
def GET(self):
form = self.form()
return render.new(form)
def POST(self):
form = self.form()
if not form.validates():
return render.new(form)
model.new_post(form.d.title, form.d.content)
raise web.seeother('/')
class Delete:
def POST(self, id):
model.del_post(int(id))
raise web.seeother('/')
class Edit:
def GET(self, id):
post = model.get_post(int(id))
form = New.form()
form.fill(post)
return render.edit(post, form)
def POST(self, id):
form = New.form()
post = model.get_post(int(id))
if not form.validates():
return render.edit(post, form)
model.update_post(int(id), form.d.title, form.d.content)
raise web.seeother('/')
app = web.application(urls, globals())
if __name__ == '__main__':
app.run()