【发布时间】:2013-04-24 11:40:18
【问题描述】:
我在图像上有链接,如果用户登录 ajax 来支持/反对很容易发生。但是,如果用户未登录,我会确保用户首先通过身份验证。
在模板中实现如下-
{% if not user.is_authenticated %}
<a href="/accounts/login/">Get Started</a>
{% else %}
<a href="my-ajax-url"> Like </a>
{% endif %}
这里的麻烦是如果用户没有登录,我希望他先登录,然后执行ajax动作。类似于 next 帮助做的事情。所以流程应该是,如果用户没有登录,他会被带到登录 url,然后自动执行 ajax 操作。
实现它的相反方式是,实现一个ajax_login_decorator,可以使用here。使用第二种方法,流程类似于:
1. The user clicks on the action button.
2. the request goes to the server, if he is not authenticated, a response is sent to client.
3. He is made to login/signup.
4. Then once he logs in, he has to click on the action button again.
相反,一个更好的方法可能是让他先登录,然后类似于 next 的东西可以执行 ajax 操作。所以问题归结为这个简单的事情 -
在用户通过身份验证后,如何使用一些 next 参数调用 ajaxy url。
【问题讨论】:
标签: python ajax django jquery django-authentication