Web.py routing seems to keep breaking

拥有回忆 提交于 2019-12-24 18:52:10

问题


For some reason, every time I run my web app it comes up with new errors, either it can't find my pages, or Attribute errors, or KeyErrors and I don't know why. I'm following a tutorial written a while back, and some web.py rules may have changed, but I can't figure out why this isn't working. Here is my controller.py file:

import web

urls = {

    '/', 'Home',
    '/register', 'Register',
    '/postregistration', 'PostRegistration'
}

render = web.template.render('Views/Templates', base='MainLayout')

# Classes / routes
class Home:
    def GET(self):
        return render.Home()

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

class PostRegistration:
    def POST(self):
        data = web.input()
        return data.username

if __name__ == '__main__':
    app = web.application(urls, globals())
    app.internalerror = web.debugerror
    app.run()

My file structure looks as follows:

controller.py
Models/
static/
    css/ [css files]
    js/ [javascript (bootstrap, jquery)
Views/
    Templates/
        MainLayout.html
        Home.html
        Register.html

I'm developing on Windows, can someone help me out?


回答1:


Your urls is written using braces {} rather than the correct parentheses (). Braces make the items a set, which does not guarantee order. Parentheses make it a tuple which does guarantee order.

web.py goes through url, two-by-two, assuming the first is the url part and the second is the class to handle it. Without a guaranteed ordering, your results, as you see, are random.



来源:https://stackoverflow.com/questions/46629812/web-py-routing-seems-to-keep-breaking

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!