Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在挂架中使用重定向时出错_Python_Pylons - Fatal编程技术网

Python 在挂架中使用重定向时出错

Python 在挂架中使用重定向时出错,python,pylons,Python,Pylons,使用1.0版的塔架: 使用《塔架手册》中的FormDemo示例: 我的控制器具有以下功能: class FormtestController(BaseController): def form(self): return render('/simpleform.html') def submit(self): # Code to perform some action based on the form data # ...

使用1.0版的塔架: 使用《塔架手册》中的FormDemo示例:

我的控制器具有以下功能:

class FormtestController(BaseController):

    def form(self):
        return render('/simpleform.html')

    def submit(self):
        # Code to perform some action based on the form data
        # ...
        h.redirect_to(controller='formtest', action='result')

    def result(self):
        return 'Your data was successfully submitted.'
首先,我注意到,在书中,作者指示导入重定向_到您执行以下导入:

from pylons.controllers.util import redirect_to
这似乎不正确,因为重定向_到routes模块中的lives,所以我将其更改为:

from routes import redirect_to
一切正常,没有更多的导入错误,但当我执行表单提交时,我看到以下回溯


有人能帮我吗?

试试:

from pylons import url
from pylons.controllers.util import redirect

# ...
redirect(url(controller='formtest', action='result'))

您最好使用当前版本和更新版本的1.0版,以及网站上的其他参考资料。

为了澄清,Pylons 0.97中已不推荐对redirect_To(和url_for)的支持,Pylons 1.0中已删除。《Pylons》一书是基于0.97编写的,因此您可能希望阅读QuickWiki页面实际上也没有完全更新Pylons 1.0(它甚至在一些地方引用了0.97)。最好的办法是在查看从bitbucket中提取的quickwiki源代码时,大致按照说明进行操作,该源代码适用于1.0。本应涵盖1.1的书是基于0的,这真让人恼火。97@qliq这也让我很恼火。我意识到1.1是这本书的文档编号——但这都是针对0.9.7版本的,而pylons是1.0.1,而不是1.1。
from pylons import url
from pylons.controllers.util import redirect

# ...
redirect(url(controller='formtest', action='result'))