Python Django没有返回表单中的语言模型
我正在本地图书馆上进行由MDN编写的Django教程 在语言模型的管理站点中,我并没有收到任何返回的错误,在那个里我必须为书籍选择语言 但在呈现书籍细节时,用户站点上的语言模型反映了错误 错误:Python Django没有返回表单中的语言模型,python,django,Python,Django,我正在本地图书馆上进行由MDN编写的Django教程 在语言模型的管理站点中,我并没有收到任何返回的错误,在那个里我必须为书籍选择语言 但在呈现书籍细节时,用户站点上的语言模型反映了错误 错误:语言:catalog.Language.none 代码和模型详细信息如下所示 <p><strong>Author:</strong> <a href="{{ book.author.get_absolute_url }}">{{ book
语言:catalog.Language.none
代码和模型详细信息如下所示
<p><strong>Author:</strong> <a href="{{ book.author.get_absolute_url }}">{{ book.author }}</a></p>
<p><strong>Summary:</strong> {{ book.summary }}</p>
<p><strong>ISBN:</strong> {{ book.isbn }}</p>
<p><strong>Language:</strong> {{ book.language }}</p>
<p><strong>Genre:</strong> {{ book.genre.all|join:", " }}</p>
类语言的models.py
class Language(models.Model):
name = models.CharField(max_length=200, help_text='Enter a book language(e.g. English)')
def __str__(self):
return self.name
models.py用于教科书
class Book(models.Model):
"""Model representing a book (but not a specific copy of a book)."""
title = models.CharField(max_length=200)
author = models.ForeignKey('Author', on_delete=models.SET_NULL, null=True)
summary = models.TextField(
max_length=1000, help_text='Enter a brief description of the book')
isbn = models.CharField('ISBN', max_length=13, unique=True,
help_text='13 Character <a href="https://www.isbn-international.org/content/what-isbn">ISBN number</a>')
genre = models.ManyToManyField(
Genre, help_text='Select a genre for this book')
language = models.ManyToManyField(
Language, help_text='Select Language for this book')
def get_language(self):
return ', '.join(language.name for language in self.language.all())
get_language.short_description = 'Language'
class Meta:
ordering = ['title', 'author']
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('book-detail', kwargs= {'pk': str(self.id)})
def display_genre(self):
return ', '.join(genre.name for genre in self.genre.all()[:3])
display_genre.short_description = 'Genre'
图书细节视图模型
class BookListView(ListView):
model = Book
class BookDetailView(DetailView):
model = Book
书籍详细视图的HTML如下所示
<p><strong>Author:</strong> <a href="{{ book.author.get_absolute_url }}">{{ book.author }}</a></p>
<p><strong>Summary:</strong> {{ book.summary }}</p>
<p><strong>ISBN:</strong> {{ book.isbn }}</p>
<p><strong>Language:</strong> {{ book.language }}</p>
<p><strong>Genre:</strong> {{ book.genre.all|join:", " }}</p>
作者:
摘要:{{book.Summary}
ISBN:{{book.ISBN}}
语言:{{book.Language}
流派:{{book.Genre.all |加入:“,”}
谢谢你我想你需要
语言:{{book.get\u Language}}。谢谢@evergreen它成功了