使用django-allauth实现Ajax请求/响应 [英] Implementing Ajax requests / response with django-allauth

查看:259
本文介绍了使用django-allauth实现Ajax请求/响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django-allauth作为我的一个项目。我想通过ajax实现登录/注册过程。我想定制注册表单。我正在通过他们的signupmixin和注册表。听起来像我可以为每个动作编写自定义视图并将其映射到url配置。我不知道这是最好的方法。



非常感谢您的任何帮助或建议。

解决方案

这取决于你对ajax的意思。如果您只想在每个页面上都有一个弹出式登录/注册框,那么您可以简单地将表单添加到基本模板中,并使用Javascript在弹出框中动态显示。如果您将表单操作网址保留到原始的 allauth urls,那么这将已经给了一个ajax登录的感觉。您也可以使用 $。ajax $。post 发布到原始 allauth 视图。



以上内容与 http: //officecheese.com/ - 这是一个 allauth 的网站,虽然我不隶属于它。



如果通过ajax,您的意思是所有认证相关视图都应通过ajax显示,而不会导致新的文档重新加载,那么我恐怕你有点不幸了。对于电子邮件验证或OAuth握手的方案来说,这是一个问题,因为您通常会从邮箱导航到新的URL,或重定向到Twitter等。


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.

解决方案

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.

Something like the above is done on http://officecheese.com/ -- this is an allauth based site, though I am not affiliated with it.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆