使用 django-allauth 实现 Ajax 请求/响应 [英] Implementing Ajax requests / response with django-allauth
问题描述
我在我的一个项目中使用了 django-allauth.我想通过ajax实现登录/注册过程.我想要定制的注册表单.我正在浏览他们的 signupmixin 和注册表单.听起来我可以为每个操作编写自定义视图并将其映射到 url 配置.我不确定这样做的最佳方法是什么.
I am using django-allauth for one of my project. I would like to implement login/signup process via ajax. I would like to have customized signup form. I was going through their signupmixin and signup form. Sounds like I can write custom views for each action and map it to the url config. I am not sure what is the best way to do this.
非常感谢您对此的任何帮助或建议.
Thank you so much for any help or advice on this.
推荐答案
这在一定程度上取决于您所说的 ajax 是什么意思.如果您只想在每个页面上都有一个弹出式登录/注册框,那么您可以简单地将表单添加到您的基本模板中,并在弹出框中使用 Javascript 动态显示它.如果您将表单操作 url 保留为原始 allauth
url,那么这已经给人一种 ajax 登录的感觉.您还可以通过使用 $.ajax
或 $.post
发布到原始 allauth
视图来进行调整.
It depends a bit on what you mean by ajax. If you just want to have a popup-style login/signup box on every page, then you can simply add the form to your base template and show it dynamically using Javascript in a popup box or so. If you keep the form action url to the original allauth
urls then this will already give the feel of an ajax signin. You could also tweak things by using $.ajax
or $.post
to post to the original allauth
views.
上面类似的事情是在 http://officecheese.com/ 上完成的——这是一个 allauth
网站,虽然我不隶属于它.
Something like the above is done on http://officecheese.com/ -- this is an allauth
based site, though I am not affiliated with it.
如果说ajax,你的意思是所有与身份验证相关的视图都应该通过ajax显示,而不会导致新的文档重新加载,那么恐怕你有点不走运.这对于涉及电子邮件验证或 OAuth 握手的场景来说是有问题的,因为在这里您通常从邮箱导航到新 URL,或重定向到 Twitter 等.
If by ajax you mean that all authentication related views should be displayed via ajax, without causing a new document reload, then I am afraid you are a little bit out of luck. This simply is problematic for scenario's where e-mail verification, or OAuth handshakes are involed, as here you are typically navigating to a new URL from your mailbox, or redirecting to Twitter and so on.
这篇关于使用 django-allauth 实现 Ajax 请求/响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!