为什么我的提交按钮在我的Django表单模板中不起作用?

时间:2014-09-26 06:58:18

标签: django django-templates

过去两天我发布了几个有关此事的问题,并且没有真正得到任何答案。基本上我想要做的就是将我自己的模板与这个Userena模板合并。原因是我想应用CSS样式,我知道如何做的唯一方法是使用My Custom Sign Up Template下的代码。自从我上次发布此问题以来,我已经取得了一些进展,因为我已将正确的ID添加到我的自定义表单中。

当我点击提交按钮时没有任何反应,我想知道我是否仅使用提交按钮发出了基本错误?或者,如果我在这里完全朝着错误的道路走下去,我想做的事情是不可能的。

我的自定义示例还有其他问题,例如,当我点击提交时,我在url字符串中看到了密码,但是现在我的问题主要是为什么我的提交按钮没有提交任何内容?

Userena注册模板

{% block title %}{% trans "Signup" %}{% endblock %}

{% block content %}
<form action="" method="post">
  {% csrf_token %}
  <fieldset>
    <legend>{% trans "Signup" %}</legend>
    {{ form.non_field_errors }}
    {% for field in form %}
    {{ field.errors }}
    {% comment %} Displaying checkboxes differently {% endcomment %}
    {% if field.name == 'tos' %}
    <p class="checkbox">
    <label for="id_{{ field.name }}">{{ field }} {{ field.label }}</label>
    </p>
    {% else %}
    <p>
    {{ field.label_tag }} 
    {{ field }}
    </p>
    {% endif %}
    {% endfor %}
  </fieldset>
  <input type="submit" value="{% trans "Sign Up"%}" />
</form>
{% endblock %}

我的自定义注册模板

<body>
  <form class="sign-up">
    <h1 class="sign-up-title">Get Started</h1>
    <input type="text" class="sign-up-input" placeholder="Name" autofocus="" id="id_username" name=username >
    <input type="text" class="sign-up-input" placeholder="Email" id="id_email" name="email">
    <input type="password" class="sign-up-input" placeholder="Password" id="id_password1" name="password1">
    <input type="password" class="sign-up-input" placeholder="Repeat" id="id_password2" name="password2">
    <input type="submit" value="Signup" class="sign-up-button">
  </form>
     </div>
</body>

1 个答案:

答案 0 :(得分:2)

您的提交无效,因为您的表单没有&#34; action =&#39;&#39;&#34;&#34;&#34; ATTR

<form class='sing-up' action='/accounts/singup/' method='post'>

并添加

{%csrf_token%}

祝你好运