简体   繁体   English

Django中的弹出UserCreationForm

[英]Popup UserCreationForm in Django

Can I popup UserCreationForm of Django? 我可以弹出Django的UserCreationForm吗?

I am building a website. 我正在建立一个网站。 When I click on signup page popup signup page needs to show. 当我单击注册页面时,弹出页面需要显示。

Right now I have a signup page and login page and they are working but I need to popup them. 现在我有一个注册页面和登录页面,它们正在工作,但是我需要弹出它们。

I am using usercreationform of Django. 我正在使用Django的usercreationform

Can I add Bootstrap and CSS in that form too? 我也可以添加Bootstrap和CSS吗?

from django.contrib.auth.forms import UserCreationForm

Here is the popup code of what i tried right now the div is showing on my page not in popup 这是我现在尝试的div的弹出代码,div显示在页面上而不是弹出窗口中

Sign-up 注册

<script src='{% static "js/grayscale.min.js" %}'></script>
      <script src='{% static "js/creative.min.js"%}'></script>
      <script type="text/javascript">
  var model= document.getElementById('abc');
  window.onclick= function(event){
    if (event.target==model) {
      model.style.display= "none";
    }
  }
      </script>  

<div id="abc">

    <div id="popupContact">
    {% block title %}

{% endblock %}
    {% block content %}

       <div class="login" style="background: grey">

         {% if messages %}
            <ul>
                {% for message in messages %}
                <li>{{ message }}</li>
                {% endfor %}
            </ul>
        {% endif %}

        <h1>Create account - Racernomics</h1>

         <form method="post" >
             {% csrf_token %}
             <table>
                {{ form.as_table }}
                 <tr>
                    <td></td>
                     <td><button type="submit">Register</button></td>
                </tr>
             </table>
         </form>
       {% endblock %}
</div>
    </div>

You can customize your form however you want. 您可以根据需要自定义表单。

It could be done by adding html-classes, id`s, etc. directly to your form class in django and then accessing and modifying them with css: 可以通过在Django的表单类中直接添加html类,id等来实现,然后使用CSS访问和修改它们:

class SomeForm(forms.Form):
    some_field = forms.DateField(widget=forms.TextInput(attrs={'class': 'datepicker', 'placeholder': 'mm/dd/yy'}),
                           required=False)

or you can use for example additional library to access form in template (I prefer this way, it helps to keep logic and frontend separate from each other). 或者您可以使用例如其他库来访问模板中的表单(我更喜欢这种方式,这有助于使逻辑和前端彼此分离)。 Such library could be widget-tweaks . 这样的库可能是小部件调整的

Take a look at this article , could be interesting for you. 看一下这篇文章 ,可能对您很有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM