1

models.py次のクラスが定義されたファイルがあります。

from django.db import models
from bands.models import Genre, Song

class Lyric(models.Model):
    """A music lyric"""
    class Meta:
        db_table = 'lyric'
    genre = models.ForeignKey(Genre)
    song = models.ForeignKey(Song,unique=True)
    lyric_text = models.TextField()
    created_at = models.DateTimeField()
    def __unicode__(self):
        return "\"" + self.title + "\" by " + self.author
    def lyric_short(self, length=100):
        return self.lyric_text[:length] + "..."

class LyricComment(models.Model):
    """Comment on a lyric"""
    class Meta:
        db_table = 'lyric_comment'
    lyric = models.ForeignKey(Lyric)
    text = models.TextField()
    author = models.CharField(max_length=64)
    ip = models.IpAddressField()
    created_at = models.DateTimeField()
    def __unicode__(self):
        return "\"" + self.text[:10] + "...\" by " + self.author
    def text_short(self, length=100):
        return self.text[:length] + "..."

実行時:

$ python manage.py syncdb

次のエラーがスローされます。

AttributeError: 'module' object has no attribute 'IpAddressField'

何が問題になっていip = models.IpAddressField()ますか?

4

2 に答える 2

4

スペルト小麦IPAddressField、大きいP

于 2013-03-14T12:30:19.610 に答える
1

これはスペルミスです。

ip = models.IpAddressField() に変更ip = models.IPAddressField()

于 2013-03-14T12:34:45.070 に答える