如何在web2py中使用全局变量?

发布于 2024-10-11 01:53:34 字数 387 浏览 8 评论 0原文

我尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只想待在家 2024-10-18 01:53:34

您可以在 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))

南城旧梦 2024-10-18 01:53:34

web2py 中没有全局变量。您可以使用cache.ram

There are no global variables in web2py. You can use cache.ram

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文