2

我有图像上的链接,如果用户登录 ajax 来支持/反对很容易发生。但是,如果用户未登录,我会确保用户首先通过身份验证。

实现在模板中完成如下 -

{% if not user.is_authenticated %}
<a href="/accounts/login/">Get Started</a>
{% else %}
<a href="my-ajax-url"> Like </a>
{% endif %}

这里的麻烦是如果用户没有登录,我希望他先登录,然后执行ajax动作。类似于下一个帮助做的事情。所以流程应该是,如果用户没有登录,他会被带到登录 url,然后自动执行 ajax 操作。

实现它的相反方法是实现ajax_login_decorator,可以像这里那样完成。使用第二种方法,流程类似于:

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 操作。所以问题归结为这个简单的事情 -

用户通过身份验证后,如何使用一些下一个参数调用 ajaxy url 。

4

1 回答 1

1

如何在第 2 步中将操作存储在(匿名)会话中,一旦他登录,您就从服务器端触发操作?您根本不必进行 AJAX 调用。

于 2013-04-30T14:44:40.007 回答