我有图像上的链接,如果用户登录 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 。