web2py - 使用锚标记回调时不会调用控制器函数 [英] web2py - Controller function isn't called when using anchor tag callback
问题描述
当用户访问杂志页面时,应该会出现一个按钮,允许当前登录的用户订阅特定杂志(如果该用户已经登录).匿名用户不应看到该按钮.
我已经让按钮在用户登录后显示,但点击按钮不会调用我的控制器功能.
如果这是控制器功能:
@auth.requires_login()定义订阅():mag_id = request.args(0, cast=int)db.subscribe.insert(杂志=mag_id,订阅者=auth.user.id)
这是视图的一部分:
{{=magazine.title}}{{=magazine.description}}<div>{{ 如果 auth.is_logged_in():}}{{=A('subscribe', _class="btn_subscribe", callback=URL("subscribe", args=magazine.id))}}{{经过}}
<a href="#null" onclick="ajax('/myapp/default/subscribe/3',[],'me');return false">subscribe</a>
控制器函数永远不会被调用,用户也永远不会订阅.
正如 Anthony 所建议的,添加 web2py.js 是解决方案.
When a user visits a magazine page, a button should appear that will allow the currently logged in user to subscribe to a particular magazine if that user is already logged in. The button should not be visible to an anonymous user.
I have gotten the button to show up when the user has logged in, but clicking on the button doesn't call my controller function.
If this is the controller function:
@auth.requires_login()
def subscribe():
mag_id = request.args(0, cast=int)
db.subscribe.insert(magazine=mag_id, subscriber=auth.user.id)
And this is the part of the views:
<div>
{{=magazine.title}}
{{=magazine.description}}
</div>
<div>
{{ if auth.is_logged_in():}}
{{=A('subscribe', _class="btn_subscribe", callback=URL("subscribe", args=magazine.id))}}
{{pass}}
</div>
The <a>
button shows up as this:
<a href="#null" onclick="ajax('/myapp/default/subscribe/3',[],'me');return false">subscribe</a>
And the controller function is never called, and the user is never subscribed.
As Anthony had suggested, adding the web2py.js was the solution.
这篇关于web2py - 使用锚标记回调时不会调用控制器函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!