![](/img/trans.png)
[英]Django - (Tagulous) AttributeError: type object 'Model' has no attribute '_meta'
[英]AttributeError: module 'tagulous' has no attribute 'models' in Django
因此,我一直在構建一個Web應用程序,對於標簽系統,我決定使用django-tagulous。 但是,當我將其導入模型時,出現此錯誤:
AttributeError: module 'tagulous' has no attribute 'models' in Django
我已將其放在settings.py的python INSTALLED_APP
列表中,並將其導入到models.py中,但仍然收到錯誤。
這是一些代碼。
models.py
import tagulous
class Post(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE)
title = models.CharField(max_length=75)
text = models.TextField()
created_date = models.DateTimeField(default=timezone.now)
image = models.ImageField(upload_to='post_images',blank=True,null=True)
published_date = models.DateTimeField(blank=True,null=True,auto_now_add=True)
NSFW = models.BooleanField(default=False)
spoiler = models.BooleanField(default=False)
interests = tagulous.models.TagField()
tags = TaggableManager()
def __str__(self):
return self.title
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
在那個Post類中,我是出於興趣而使用它的。
這是我的forms.py PostForm
class PostForm(forms.ModelForm):
class Meta():
model = Post
fields = ['title','text','image','interests','spoiler','NSFW']
widgets = {
'title':forms.TextInput(attrs={'class':'textinputclass'}),
'text':forms.Textarea(attrs={'class':'textareaclass editable'}),
}
def __init__(self, *args, **kwargs):
super(PostForm, self).__init__(*args, **kwargs)
self.fields['image'].required = False
到目前為止,我沒有在網上找到有關此錯誤的信息。 我期望它能正常工作,但是不,謝謝:)
好吧,我繼續深入研究他們的文檔,結果發現他們有一些鮮為人知的模型導入選項。
我找到了他們的一些文檔。 您需要導入他們的模型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.