我如何在python POST方法中调用通配符变量?

时间:2017-09-14 00:27:51

标签: python python-2.7 wildcard web.py

我仍然对python很新鲜,并且我试图让我的web应用程序返回一个通配符变量(作为一个全能)。这是我当前的代码,它对于定义的字典路径以及空表单响应都能正常运行,但是我无法让它对未定义的条目起作用:

def POST(self):
    form = web.input(action=None)

    if session.room:
        if form.action:
            session.room = session.room.go(form.action)
        if not form.action:
            web.seeother("/")
        return render.show_room(room=session.room)

    else:
        web.seeother("/")

这是我的字典,供我参考的内容('*'是通配符全能):

escape_pod.add_paths({
    '2': the_end_winner,
    '*': the_end_loser
})

the_bridge.add_paths({
    'throw the bomb': bridge_death,
    'slowly place the bomb': escape_pod,
    '*': the_bridge
})

laser_weapon_armory.add_paths({
    '132': the_bridge,
    '*': laser_death
})

central_corridor.add_paths({
    'shoot!': shoot_death,
    'dodge!': dodge_death,
    'barrel roll': poor_sport,
    'tell a joke': laser_weapon_armory,
    '*': central_corridor
})

poor_sport.add_paths({
    'let me try again': central_corridor,
    '*': poor_sport
})

我已经让它工作一次但由于某种原因我的编辑器没有在本地文件历史记录中保存该版本?欢迎任何帮助..谢谢!

这是我终端的堆栈跟踪。我知道这个问题,我似乎无法弄清楚如何重新调用我的函数来调用通配符。

Traceback (most recent call last):
  File "/Users/isabey/anaconda/lib/python2.7/site-
packages/web/application.py", line 239, in process
    return self.handle()
  File "/Users/isabey/anaconda/lib/python2.7/site-
packages/web/application.py", line 230, in handle
    return self._delegate(fn, self.fvars, args)
  File "/Users/isabey/anaconda/lib/python2.7/site-
packages/web/application.py", line 462, in _delegate
    return handle_class(cls)
  File "/Users/isabey/anaconda/lib/python2.7/site-
packages/web/application.py", line 438, in handle_class
    return tocall(*args)
  File "/Users/isabey/projects/gothonweb/bin/app.py", line 48, in POST
    return render.show_room(room=session.room)
  File "/Users/isabey/anaconda/lib/python2.7/site-
packages/web/template.py", line 1020, in template
    return self._base(t(*a, **kw))
  File "/Users/isabey/anaconda/lib/python2.7/site-
packages/web/template.py", line 881, in __call__
    return BaseTemplate.__call__(self, *a, **kw)
  File "/Users/isabey/anaconda/lib/python2.7/site-
packages/web/template.py", line 808, in __call__
    return self.t(*a, **kw)
  File "templates/show_room.html", line 19, in __template__
    $room.description
AttributeError: 'NoneType' object has no attribute 'name'

0 个答案:

没有答案