django如何根据模态处理登录/注册? [英] How does django treat login/signup based on modal?
问题描述
我在 django
中使用modal for login / signup
。
( http://bootsnipp.com/snippets/featured/ modal-login-with-jquery-effects )
I'm using modal for login/signup
in django
.
(http://bootsnipp.com/snippets/featured/modal-login-with-jquery-effects)
但我想知道 django
如何处理模板渲染。
But I wonder how django
treat this in template rendering.
正如你在上面看到的url,它只有一个 html
文件,比如说, login.html
。
As you can see above url, it has only one html
file, say, login.html
.
在django views
中,我有两个观点名为 LoginView
和 SignupView
。
In django views
, I have two views named LoginView
and SignupView
.
这些是我的意思认为是问题。
These are what I thought as problems.
-
每个
查看
将呈现模板
:
-
LoginView
- >login.html
-
SignupView
- >signup.html
LoginView
-->login.html
SignupView
-->signup.html
但是你可以看到上面,如果我使用模态,注册
和<$ c $只有一个 html
文件C>登录。我想知道如何处理它。
but as you can see above, if I used modal, there is only one html
file for both signup
and login
. I want to know how I can deal with it.
- 此外,每个
视图
要传递表格
,比如说,UserCreationForm
,CustomLoginForm
用于获取用户的输入。但如果只有一个html
文件,那些表格
之间会有冲突吗?
- Also, Each
view
gonna pass itsform
, say,UserCreationForm
,CustomLoginForm
for getting input from user. But if there were only onehtml
file, would there be conflict between thoseforms
?
谢谢。
推荐答案
1)你可以同时移动两个它们进入一个视图,返回两个不同名称的表单。
1) You can move both of them into one view that returns both of the forms, with different names.
signup_form = UserCreationForm()
login_form = CustomLoginForm()
context = {"signup_form": signup_form, "login_form": login_form, **other_kwargs}
return render(request, context, content_type=...)
2)包含多个表单的页面没有问题。由于表单以不同的名称呈现,一个想法是使用隐藏的输入区分哪个表单被发布,所以基本上在你的html中,你做了类似的事情:
2) There's no problem with a page that contains several forms. Since the forms are being rendered in different names, one idea is to distinguish which form gets posted, using a hidden input, so basically in your html, you do something like:
<form method="POST" action="URL">
input type="hidden" name="form_name" value="login_form"
{{ login_form.as_table }}
input type="submit"
</form>
<form method="POST" action="URL">
input type="hidden" name="form_name" value="signup_form"
{{ signup_form.as_table }}
input type="submit"
</form>
您还可以将URL指向单个视图,使用其中的form_name键处理提交的表单POST参数。或者您可以让他们指向其他网址,发送ajax请求或您喜欢的任何其他方式。
You can also point URL to a single view, handle which form was submitted using the form_name key inside the POST parameters. Or you can have them point to other URLs, send ajax requests or any other way you prefer.
这篇关于django如何根据模态处理登录/注册?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!