简体   繁体   English

web.py中的模板

[英]Templates in web.py

I try to render a template with web.py and some seconds after another, I'm not too much into Python so I could need a little help :). 我尝试用web.py渲染模板,然后几秒钟之后渲染一个模板,我对Python不太了解,所以我需要一些帮助:)。

What I try to achive (return can be returned only once for sure, but I guess you'll get it what I mean) 我尝试达到的目标(肯定只能返回一次,但是我想您会明白我的意思的)

class index: 
    def GET(self):
        return render.formone('')
        time.sleep(30)
        return render.formtwo('')

So I need to get around that return somehow, but I have no idea how... 所以我需要以某种方式解决回报问题,但是我不知道如何...

Thanks for answers! 感谢您的回答!

Why would you want to render two forms at the same time? 为什么要同时渲染两个表单? You simply cannot send two responses this way. 您根本无法通过这种方式发送两个回复。 Your script will end after first return. 您的脚本将在首次返回后结束。

If I understand you correctly, you want to serve two forms at the same time (meaning you want to join them)? 如果我对您的理解正确,那么您想同时提供两种形式(意味着要加入它们)吗? If yes, then look at this example . 如果是,则查看此示例 Basically you first render both forms 基本上你先渲染两种形式

formone = render.formone('') 
formtwo = render.formtwo('') 

And then join them and send the response 然后加入他们并发送回复

return render.index(unicode(formone), unicode(formtwo))

If you don't want to serve them at the same time, this can't be done this way. 如果您不想同时为他们提供服务,则无法通过这种方式完成。 You may do this via AJAX (ie event from webpage, send request and ask for second form after clicking on some element or whatever) or sending another standard non-async request (submitting first form). 您可以通过AJAX (例如,来自网页的事件,发送请求并在单击某些元素或其他内容后请求第二种形式)或发送另一个标准的非异步请求(提交第一种形式)来进行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM