Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python can';t导入名称';邮政';_Python_Django_Import - Fatal编程技术网

Python can';t导入名称';邮政';

Python can';t导入名称';邮政';,python,django,import,Python,Django,Import,我无法在django模型中导入类帖子,当我尝试运行服务器时,它返回importError:Cannotimportname“Post”,我已经做了几天了,请帮助我..谢谢 这是我的班级模型 from .models import Post, Comment class Post(models.Model): objects = models.Manager() published = PublishedManager() def get_absolute_u

我无法在django模型中导入类帖子,当我尝试运行服务器时,它返回importError:Cannotimportname“Post”,我已经做了几天了,请帮助我..谢谢

这是我的班级模型

from .models import Post,  Comment

class Post(models.Model):
     objects = models.Manager() 
     published = PublishedManager()

     def get_absolute_url(self):
         return reverse('blog:post_detail',args=[self.publish.year,self.publish.strftime('%m'), self.publish.strftime('%d'),self.slug])

    STATUS_CHOICES = (('draft', 'Draft'),('published', 'Published'),)
    title = models.CharField(max_length=250)
    slug = models.SlugField(max_length=250, 
    unique_for_date='publish')
    author = models.ForeignKey(User,
    related_name='blog_posts')
    body = models.TextField()
    publish = models.DateTimeField(default=timezone.now)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    status = models.CharField(max_length=10, 
    choices=STATUS_CHOICES,default='draft')
class Meta:
     ordering = ('-publish',)
     def __unicode__(self):
         return self.title
这也是我的课堂教学模式

from .models import Post,  Comment

class Comment(models.Model):
    post = models.ForeignKey(Post, related_name='comments')
    name = models.CharField(max_length=80)
    email = models.EmailField()
    body = models.TextField()
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    active = models.BooleanField(default=True)
class Meta:
    ordering = ('created',)
    def __unicode__(self):
     return 'Comment by {} on {}'.format(self.name, self.post)

为什么要尝试将Post和Comment模型导入到定义它们的同一个文件中?没有理由这样做;删除这些导入行。

为什么要尝试将Post和Comment模型导入到定义它们的同一文件中?没有理由这样做;删除那些导入行