Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

how can i open a modal from views.py in django? Is there any way?

I have a django application. when a user clicks the submit button two modals should be shown one after another each has to do different functions in views.py in my django app. I am trying to write the code but the problem is not easy and I have looked everywhere and couldn't get the answer.

I have to write the code in the following way:

views.py

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

and when the user clicks any of the buttons each should also call the different function in 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>
question from:https://stackoverflow.com/questions/65914399/how-can-i-open-a-modal-from-views-py-in-django-is-there-any-way

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could do that by using the modal system from the bootstrap documentation, you can check the live demo

In your template use a condition with Jinja2 if first condition show modal 1, else show modal 2, just make sure you have 2 different ID for the modal so they open distinctly


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...