如何在django中从views.py中打开一个模态?有办法吗?



我有一个django应用程序。当用户点击提交按钮两种模式应该显示一个接一个,每个必须做不同的功能在views.py在我的django应用程序。我试图写代码,但问题是不容易的,我已经到处看,不能得到答案。

我必须按照以下方式编写代码:

views.py

def submit(request):
#first modal should pop up which has two options.
#second modal should pop up which also has a two options.

,当用户单击任何按钮时,每个按钮也应该调用views.py中的不同函数。

html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

<button class="btn btn-danger custom" style="position:absolute; left:800px; top:180px;" type="submit">Update the data</button>


# user clicks a button in form and modal should pop up
# then 2 modals should pop up
# the first modal has two buttons 
# when user clicks the update button the function in the views should be called and also 2nd modal 
should pop up

<!--modal 1-->
<div aria-hidden="true" aria-labelledby="exampleModalLabel" class="modal fade" id="UpdateModal" role="dialog"
tabindex="-1">

<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Update Changes</h5>
<button aria-label="Close" class="close" data-dismiss="modal" type="button">
<span aria-hidden="true">&times;</span>
</button>
</div>
#when user clicks update button another modal should pop up as well as 
another function in the views should be called.
</body>
</html>

你可以通过使用引导文档中的模态系统来实现,你可以查看实时演示

在你的模板中使用Jinja2如果第一个条件show modal 1, elseshow modal 2,只要确保你有两个不同的模态ID,这样它们就可以独立打开

最新更新