Error in form django

1

I'm trying to run a form in django but it returns this error

form = TopicoForm() 



raise ValueError('ModelForm has no model class specified.')

this is my models

class Topico(models.Model):

    titulo = models.CharField('Título', max_length=100)
    mensagem = models.TextField('Mensagem')
    avatar = models.ImageField(upload_to='core/images', verbose_name='Imagem', blank=True, null=True)
    id_usuario = models.ForeignKey(Usuario)
    id_assunto = models.ForeignKey(Assunto)

    def __str__(self):
        return self.titulo

o form

class TopicoForm(forms.ModelForm):

    class meta:
        model = Topico
        fields = '__all__'

and a views

def novo_post(request):
    if request.POST:
        form = TopicoForm(request.POST)
        if form.is_valid:
            form.save()

    else:
        form = TopicoForm()
    contexto = {
        "form": form
    }
    return render(request, "novo_post.html", contexto)
    
asked by anonymous 25.11.2017 / 01:19

1 answer

1

The error occurred because you wrote meta instead of Meta , the correct one would be:

class TopicoForm(forms.ModelForm):

    class Meta:
        model = Topico
        fields = '__all__'
    
25.11.2017 / 21:27