Send form Django

0

I'm new to python and I'm trying to make a registration, when I click send nothing happens, no post

views.py

    from django.http import HttpResponse
    from django.shortcuts import render
    from portal.cadastro.forms import CadastroForm
    from django.shortcuts import redirect
    from models import *

    def cadastro(request):
    if request.method == 'POST':
        return create(request)
    else:
        return new(request)


def new(request):
    return render(request, 'cadastro1.html',
                {'form': CadastroForm()})


def create(request):
    form = CadastroForm(request.POST)
    if not form.is_valid():
        return render(request, 'cadastro1.html',
                    {'form': form})
    obj = form.save()
    return HttpResponseRedirect('/cadastro1')

cadastro1.html

 <div class="row">
     <div class="col s12">
<form action="." method="POST">

<div class="card white darken-1">
    <div class="card-content black-text">
 <p>
<label for="{{ form.email.id_for_label }}">{{ form.email.label }}:</label>
{{ form.email }}
{{ form.email.errors }}
</p>

<p>
<label for="{{ form.nome.id_for_label }}">{{ form.nome.label }}:</label>
{{ form.nome }}
{{ form.nome.errors }}
</p>
<p>

 <label for="{{ form.divisao.id_for_label }}">{{ form.divisao.label }}:</label>
  <select class="browser-default">
    <option value= {{form.divisao}}>{{form.divisao}}</option>
  </select>
{{ form.divisao }}
{{ form.divisao.errors }}
</p>

<p>
<label for="{{ form.vinculo.id_for_label }}">{{ form.vinculo.label }}:</label>
    <select class="browser-default">
        <option value={{form.vinculo}}>{{form.vinculo}}</option>
          </select>
</p>

<button class="btn waves-effect waves-light" type="submit" name="enviar">Enviar
    <i class="material-icons right" >send</i>
  </button>
</div>
    </div>
    </form>
    </div>

</div>

models.py

DIVISOES = (
    (u'SSS', u'SSS'),
    (u'Banco de Dados', u'Banco de Dados'),
    (u'Redes', u'Redes'),
    (u'Outros', u'Outros'),
    )


VINCULOS = (
    (u'Bolsista', u'Bolsista'),
    (u'Estagiário', u'Estagiário'),
    (u'Terceiro', u'Terceiro'),
    (u'Servidor', u'Servidor'),
    )




# Create your models here.
class Usuario(models.Model):
    email = models.EmailField(blank=True)
    nome = models.CharField(max_length=255)
    divisao = models.CharField(max_length=255, choices=DIVISOES)
    vinculo = models.CharField(max_length=255, choices=VINCULOS)

    def __unicode__(self):
        return self.email

    class Meta:
        verbose_name = u'Usuário'
        verbose_name_plural = u'Usuários'

forms.py

DIVISOES = (
    (u'SSS', u'SSS'),
    (u'Banco de Dados', u'Banco de Dados'),
    (u'Redes', u'Redes'),
    (u'Outros', u'Outros'),
    )


VINCULOS = (
    (u'Bolsista', u'Bolsista'),
    (u'Estagiário', u'Estagiário'),
    (u'Terceiro', u'Terceiro'),
    (u'Servidor', u'Servidor'),
    )


class CadastroForm(forms.Form):
    email = forms.EmailField(label='Email')
    nome = forms.CharField(label='Nome')
    divisao = forms.ChoiceField(widget=forms.Select, choices=DIVISOES, label='Divisão')
    vinculo = forms.ChoiceField(widget=forms.Select, choices=VINCULOS, label='Vinculo')

class CadastroForm(forms.ModelForm):
    class Meta:
        model = Usuario
        fields = '__all__'
    
asked by anonymous 09.08.2017 / 19:06

1 answer

-1

Your form is pointing to the root of the site. change this:

<form action="." method="POST">

for this:

<form method="POST">
    
30.08.2017 / 04:49