【问题标题】:How two or more templates can be rendered in web.py?如何在 web.py 中呈现两个或多个模板?
【发布时间】:2015-03-24 05:45:19
【问题描述】:

我正在尝试使用 web.py 运行两个模板,但以下代码给出了以下错误。[500 内部服务器]

感谢您的帮助!

import web
import pymongo
import datetime


render =  web.template.render('templates/')

urls = (
    '/', 'login'
    '/index', 'index'
)

app = web.application(urls, globals())

web.config.debug= False



class login:    
    def GET(self):   
        return render.login()

    def POST(self):   
        i=web.input()
        print i

class index:
    def GET(self):   
        return render.index()

        def POST(self):   
        i=web.input()
        print i

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

追溯:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/application.py", line 239, in process
    return self.handle()
  File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/application.py", line 230, in handle
    return self._delegate(fn, self.fvars, args)
  File "/usr/local/lib/python2.7/dist-packages/web.py-0.37-py2.7.egg/web/application.py", line 419, in _delegate
    cls = fvars[f]
KeyError: u'login/index'

127.0.0.1:44423 - - [24/Mar/2015 11:03:17] "HTTP/1.1 GET /" - 500 Internal Server Error

【问题讨论】:

    标签: mongodb python-2.7 pymongo ubuntu-14.04 web.py


    【解决方案1】:

    缺少逗号:

    urls = ( '/', 'login', '/index', 'index' )
    #                HERE^
    

    仅供参考,这是没有逗号的情况:

    >>> urls = ( '/', 'login' '/index', 'index' )
    >>> urls
    ('/', 'login/index', 'index')
    

    【讨论】:

    • @Dave 很高兴为您提供帮助,不要忘记接受答案。谢谢。
    猜你喜欢
    • 2015-11-26
    • 1970-01-01
    • 2014-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-14
    • 1970-01-01
    相关资源
    最近更新 更多