当我编辑配置文件并保存时,提交按钮不起作用,并且表单也没有保存。 我的views.py
class EditProfile(LoginRequiredMixin, UserPassesTestMixin, SuccessMessageMixin, PreviewMixin, generic.UpdateView):
model = models.ParentProfile
form_class = forms.ParentProfileForm
template_name = "profiles/edit_profile.html"
preview_template_name = "profiles/edit_profile_preview.html"
success_url = reverse_lazy('profiles:show_self')
def form_valid(self, form):
reactivation_required = False
for field in type(self.object).reactivation_required_fields():
if self.object.has_changed(field):
reactivation_required = True
break
if not reactivation_required or self.security_hash(form) == self.request.POST.get('hash', '0'):
return self.done(form)
self.process_preview(form)
self.stage = 2
# self.request.POST['hash'] = self.security_hash(form)
print(self.request.POST['hash'], 'agus', self.security_hash(form))
form = self.get_form(self.get_form_class())
return self.render_to_response(self.get_context_data(form=form))
def test_func(self, user):
return user.is_parent()
def get_object(self, queryset=None):
return self.request.user.get_profile()
并在我的edit_profile_preview.html
中<form action="" method="post">{% csrf_token %}
{% for field in form %}{{ field.as_hidden }}
{% endfor %}
<input type="submit" class="btn btn--default" value="{% trans "Yes, I understand" %}" />
<a class="btn btn--secondary" href="{% url 'profiles:show_self' %}">{% trans 'Cancel' %}</a>
</form>
{% block form_message %}
{% endblock %}
并且此模板中的“提交”按钮不起作用。