javascript django 形式为弹出对话框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31144057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 13:21:31  来源:igfitidea点击:

django forms as a pop up dialogue

javascriptjquerypythonhtmldjango

提问by shizznetz

I just created a django form using this following documentation:https://docs.djangoproject.com/en/1.8/topics/forms/

我刚刚使用以下文档创建了一个 django 表单:https: //docs.djangoproject.com/en/1.8/topics/forms/

My Forms.py is similar to this:

我的 Forms.py 与此类似:

from django import forms

class NameForm(forms.Form):
    your_name = forms.CharField(label='Your name', max_length=100)

My Html template is similar to this (from django doc):

我的 Html 模板与此类似(来自 django doc):

<dialog id="addForm">
    <form action="{% url "listing" %}" method="post" >
    {% csrf_token %}
    {{ form }}

    <input id="task_submit" type="submit" value="Submit"/>
    </form>
</dialog>

<button onlick="PopUp()">Add Listing </button>

<script>

function PopUp(){
    document.getElementByID("addForm").showModal();
}

</script>

However, I want my form to be a pop up dialogue when a user clicks on a button called "add tasks". I do not want the form to show until the user clicks a button called "add tasks". I have not been able to find any methods so far to do so while using Django Forms.

但是,当用户单击名为“添加任务”的按钮时,我希望我的表单是一个弹出对话框。在用户单击名为“添加任务”的按钮之前,我不希望表单显示。到目前为止,在使用 Django Forms 时,我还没有找到任何方法可以做到这一点。

Question: How do I implement a pop up dialogue to display my current django form when a user clicks on a button?

问题:当用户单击按钮时,如何实现弹出对话框以显示我当前的 django 表单?

回答by shizznetz