开发者

How to use global variable in web2py?

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.ht开发者_JAVA技巧ml: 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?


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))


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜