[Fixed]-Django Help: AttributeError: 'module' object has no attribute 'Charfield'

56👍

That is CharField, with uppercase ‘f’, and not Charfield as in your code.

12👍

I think in forms.py you are using

from django.forms import forms

Please use this

from django import forms

3👍

change charfield to:

CharField(max_length = 10)

both C and F should be capitalized

1👍

This :

  question = models.CharField(max_length=200)

Instead of :

  question = models.Charfield(max_length=200)

0👍

I have the same error but following code works for me:

from django.db import models
#Create your models here.

class Question(models.Model):
    question_text = models.CharField(max_length=100)
    pub_date = models.DateTimeField('date published')

class Choice(models.Model):
    choice_text = models.CharField(max_length = 200)
    votes = models.IntegerField(default =0)
    question = models.ForeignKey(Question, on_delete=models.CASCADE)

Simply change charfield() to charField() ..

0👍

In model Poll, spelling of CharField is not properly formatted. Ie you have written a small letter f inplace of a capital letter F. So, replace Charfield by CharField. You can see the code below:

from django.db import models

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published') class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice = models.CharField(max_length=200)
    votes = models.IntegerField()
👤suraz

0👍

Use this
from django.db import models

Leave a comment