A
A
Ayaks772018-02-04 20:25:11
Django
Ayaks77, 2018-02-04 20:25:11

Django 405 Method Not Allowed?

I can't figure out what's going on:
models:

class Contact(models.Model):
    name = models.CharField('Имя', max_length=30)
    email = models.CharField('Email', max_length=40)

form:
class ContactForm(ModelForm):
    class Meta:
        model = Contact
        fields = ('name', 'email')

view:
class ContactFormView(FormView):
    form_class = ContactForm
    template_name = 'contact.html'
    success_url = '/'

    def form_valid(self, form):
        form.save()
        username = form.cleaned_data['username']
        email = form.cleaned_data['email']
        contact = Contact.objects.create(username=username, email=email)
        contact.save()
        return HttpResponseRedirect(self.get_success_url())

template:
<div id="myModal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title">Запись на курс</h4>
      </div>
      <div class="modal-body">
          <form  method="post">
          {% csrf_token %}
          {{ my_form.as_p }}
          <button class='' type="submit">Записаться</button>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Закрыть</button>
        <button type="button" class="btn btn-primary">Сохранить изменения</button>
      </div>
    </div>
  </div>
</div>

url:
url(r'^contact-form/$', ContactFormView.as_view(), name='contact'),

the first url in the list
does not save the model, there is no redirect, the form opens on click, done on bootstrap without using js, but I think it doesn't matter

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question