Django表单提交不起作用

时间:2017-02-11 17:15:07

标签: django django-forms django-templates

我有一个我想要填充的EventForm表单。我使用event_form.attributes所以我可以自定义CSS。但是当我点击提交时没有任何反应 - 动作网址未被调用或任何其他内容。

EventForm:

class EventForm(forms.ModelForm):
    name = forms.CharField(max_length=128, help_text="Enter event name")
    description = forms.CharField(max_length=1024, help_text="Enter event description")
    date_str = forms.CharField(max_length=128,label="Date", help_text="Enter date in the format: DD/MM/YY")
    address = forms.CharField(max_length=128, help_text="Enter event address")
    image = forms.ImageField(label="Event Image")
    volunteerLimit = forms.IntegerField(initial=10, label="Volunteer Limit")
    category = forms.ChoiceField(choices=CATEGORY_SELECT, required=True)
    mininumAge = forms.IntegerField(initial=18, label="Minimum Age")
    closed = forms.BooleanField(widget=forms.HiddenInput(),initial=False)

    class Meta:
        model = Event
        exclude = ( 'date', 'slug', 'volunteers', "organisation" )

base.html文件

        {% csrf_token %}
          <form id="event_form" method="post" action="/iVolunteer/add_event/">
          {% for hidden in event_form.hidden_fields %}
              {{ hidden }}
          {% endfor %}
                <div class="form-group">
                  {{ event_form.name.errors }}
                  {{ event_form.name.label_tag }}
                  {{ event_form.name|addclass:"form-control form-style"}}
                </div>
                <div class="form-group">
                    {{ event_form.description.errors }}
                    {{ event_form.description.label_tag }}
                    {{ event_form.description|addclass:"form-control form-style"}}
                </div>
                <div class="form-group">
                    {{ event_form.date_str.errors }}
                    {{ event_form.date_str.label_tag }}
                    {{ event_form.date_str|addclass:"form-control form-style"}}
                </div>
                <div class="form-group">
                    {{ event_form.address.errors }}
                    {{ event_form.address.label_tag }}
                    {{ event_form.address|addclass:"form-control form-style"}}
                </div>
                <div class="form-group">
                    {{ event_form.category.errors }}
                    {{ event_form.category.label_tag }}
                    {{ event_form.category|addclass:"form-control form-style"}}
                </div>
                <div class="form-group">
                    {{ event_form.mininumAge.errors }}
                    {{ event_form.mininumAge.label_tag }}
                    {{ event_form.mininumAge|addclass:"form-control form-style"}}
                </div>
                <div class="form-group">
                    {{ event_form.volunteerLimit.errors }}
                    {{ event_form.volunteerLimit.label_tag }}
                    {{ event_form.volunteerLimit|addclass:"form-control form-style"}}
                </div>
                <div class="form-group">
                    {{ event_form.image.errors }}
                    {{ event_form.image.label_tag }}
                    {{ event_form.image|addclass:"form-control form-style"}}
                </div>


            <div class="modal-footer">
              <input type="submit" class="btn btn-default btn-standard" name="submit" value="Create Event" data-dismiss="modal">
            </div>

            </form>

非常感谢任何评论或建议。谢谢。

1 个答案:

答案 0 :(得分:0)

如果您不在/iVolunteer/add_event/,请尝试放置action=""。将{% csrf_token %}放在表单中。