python - LoginForm django 模式
问题描述
我尝试在我的标题上的弹出窗口(模式)上添加一个基于 django 的 LoginForm fonction 的登录表单。但它不起作用......我不知道我做错了什么......当我在 login.html 之类的页面上使用 LoginForm 时,我可以工作,但是当我在弹出页面上尝试时什么也没有。这是我的页面 popup.html 和我的页面网址。谢谢你
from django.urls import path
from django.contrib.auth import views as auth_views
from .forms import LoginForm
from . import views
app_name = 'account'
urlpatterns = [
path('', auth_views.LoginView.as_view(template_name='shop/popup.html', redirect_authenticated_user=True, authentication_form=LoginForm), name='login'),
]
<!-- Trigger/Open The Modal -->
<button id="myBtn">Open Modal</button>
<!-- The Modal -->
<div id="myModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>Modal Header</h2>
</div>
<div class="modal-body">
{{ form }}
{# <form>#}
{# <div class="form-group col">#}
{# <div class="col-xs-2">#}
{# <label for="Email">Email address</label>#}
{# <input type="email" class="form-control mb-6" id="Email"#}
{# aria-describedby="emailHelp"#}
{# placeholder="Enter email">#}
{# </div>#}
{# <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone#}
{# else.</small>#}
{##}
{# <div class="col-xs-2">#}
{##}
{# <label for="exampleInputPassword1">Password</label>#}
{# <input type="password" class="form-control mb-6" id="exampleInputPassword1"#}
{# placeholder="Password">#}
{# <div class="col-xs-2">#}
{# </div>#}
{# </div>#}
{# </div>#}
{# <button type="submit" class="btn btn-primary">Submit</button>#}
{# </form>#}
</div>
<div class="modal-footer">
<h3>Modal Footer</h3>
</div>
</div>
<script>
// Get the modal
var modal = document.getElementById("myModal");
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on the button, open the modal
btn.onclick = function () {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function () {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
解决方案
看看支持模式的引导程序 v5。这是引导程序 5 模式的直接链接:https ://getbootstrap.com/docs/5.0/components/modal/
在使用任何引导程序之前,您必须在 HTML 页面的标题中包含以下标签
只需复制它们并粘贴到标题标签中,这里就是“之前要做什么”信息链接:https ://getbootstrap.com/docs/5.0/getting-started/introduction/
希望它变得有帮助。谢谢你
推荐阅读
- angular - 具有可扩展行的角材料表 - 将子表的列排列在彼此下方
- java - Apache Tomcat 升级到 8.5.51 导致 400 错误
- ruby - 在纯 Ruby 中获取时区(无轨道)
- python - 在另一个方法中调用不同的方法
- python - 从 PYTHON 在线 IDE 和 PYCHARM 获得不同的结果。EOF 错误
- c++ - 如何输出一个真正不同的随机结果,从 C++ 中的一串数组中提取?
- php - 查询两个 Woocommerce 标准表
- javascript - loadable component require not found with webpack
- java - Returning Hapi FHIR element in restful server
- vb.net - 如果我在代码上创建了“项目”,如何获得它