0
I have been studying Django recently, but I came across a problem in creating forms, I tried to go in the official Framework documentation but I could not find the solution.
Forms.py
from django import forms
from .models import Novo_Usuario
class FormNovoUsuario(forms.Form):
nome = forms.CharField(max_length=200, label='nome')
sobrenome = forms.CharField(max_length=200, label='sobrenome')
senha = forms.CharField(max_length=50, label='senha')
class Meta:
fields = ('nome', 'sobrenome', 'senha')
models = Novo_Usuario
py.models
from __future__ import unicode_literals
from django.db import models
class Novo_Usuario(models.Model):
nome = models.CharField(max_length=200)
sobrenome = models.CharField(max_length=200)
senha = models.CharField(max_length=50)
def __str__(self):
return self.nome
py views.
from __future__ import unicode_literals
from django.shortcuts import render
from django.http import HttpResponse
from .models import Novo_Usuario
from .forms import FormNovoUsuario
def cms(request):
return render(request, 'base.html')
def cad_novo_usuario(request):
form = FormNovoUsuario(request.POST or None)
if request.method == 'POST':
return form.save()
return render(request, 'novo_usuario.html', {'form': form})
What problem did you find? Explain better where you are struggling
– Vinicius Macelai
Maybe the error is in the save() attribute, because the error I get is 'Formnovousuario' Object has no attribute 'save'
– Henrique Nascimento