如何在web2py中使用全局变量?
我尝试在 web2py 中创建一个名为 temp 的全局变量,但显然即使我尝试将用户输入存储到 temp,该变量的值也不会改变。它只是保持不变(温度 = 0.0)。怎么了?
这是default.py: http://pastebin.com/dafZZjJx
这是index.html:pastebin.com/Lw21Gg15
在将图像创建到HTML页面时是否有其他方法将用户输入发送到函数?我使用了以下行
image=URL(r=请求,f='nonhomog_plot')
制作图像,但如果我想在不使用全局变量的情况下将用户输入发送到 nonhomog_plot ,正确的语法是什么?
I tried to create a global variable called temp in web2py, but apparently the value of the variable doesn't change even if I try to store the user input to temp. It just stays the same (temp = 0.0). What's wrong?
Here is the default.py: http://pastebin.com/dafZZjJx
Here is the index.html: pastebin.com/Lw21Gg15
Is there any other way to send user input to functions when creating images to HTML page? I have used the following line
image=URL(r=request,f='nonhomog_plot')
to make the image but what is the correct syntax, if I want to send the user input to nonhomog_plot without using a global variable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 web2py 中使用全局变量,但它们不是持久的。如果您愿意,您可以在会话中存储温度。 (顺便说一句,无需在仅阅读的上下文中声明全局变量。)
或者,将其传递到 URL 的查询字符串中:
image = URL('nonhomog_plot', vars=dict(nu=str (value)))
或者在您的情况下,因为您已经在 vars 中收到 nu :
image = URL('nonhomog_plot', vars=request.vars)
或仅包含 nu :
image = URL('nonhomog_plot', vars=dict(nu=request.vars.nu))
You can use globals in web2py, but they're not persistent. You could store temp in session if you like. (BTW, there's no need to declare a global in a context where you're only reading it.)
Alternatively, pass it in your URL's query string:
image = URL('nonhomog_plot', vars=dict(nu=str(value)))
or in your case, since you're receiving nu in vars already:
image = URL('nonhomog_plot', vars=request.vars)
or to include only nu:
image = URL('nonhomog_plot', vars=dict(nu=request.vars.nu))
web2py 中没有全局变量。您可以使用cache.ram
There are no global variables in web2py. You can use cache.ram