我是Django的新手。我正在用django 1.9创建一个博客页面。我正在尝试创建一个关于页面,可以使用图像和管理页面中的一些内容进行更新。当我转到about页面时,它不会显示任何内容。看来模型没有返回任何东西。我不确定我错在哪里。
以下是我的网页代码。
models.py
Process
views.py
class About(models.Model):
image = models.ImageField()
about_body = models.TextField()
slug = models.SlugField(max_length=200, unique=False)
objects = AboutAuthor.as_manager()
def __str__(self):
return self.image
def get_absolute_url(self):
return reverse("about_author", kwargs={"slug": self.slug})
class AboutAuthor(models.QuerySet):
def published(self):
print("ABOUTAUTHOR: {}".format(self.all()))
return self.all()
urls.py
class About(generic.ListView):
queryset = models.About.objects.published()
print("inside About view queryset={}".format(queryset))
model = models.About
template_name = "About.html"
home_page.html
urlpatterns = [
url(r'^$', views.VBlogIndex.as_view(), name="index"),
url(r'^entry/(?P<slug>\S+)$', views.VBlogDetail.as_view(), name="entry_detail"),
url(r'^about/$', views.About.as_view(), name='about_author'),
url(r'^feed/$', feed.LatestPosts(), name="feed"),
]
About.html
<li><a href="{{ about_author.get_absolute_url }}/about">About</a></li>
当我在About.html的页面源中运行时,我得到了
{% load django_markdown %}
{% load embed_video_tags %}
{% block blog_entries %}
<div class='post-outer'>
<article class='post hentry'>
<header class='entry-header'>
<h1 class='post-title entry-title'>
About the Author
</h1>
</header>
<div class='post-header-line-1'></div>
<div class='post-body entry-content'>
<div>
<div class="separator" style="clear: both; text-align: center;">
<img src="{{objects.image}}" class="pbtthumbimg"/>
</div>
<div>{{ objects.about_body|markdown }}</div>
</div>
<div style='clear: both;'></div>
</div>
</article>
<div style='clear: both;'></div>
</div>
{% endblock %}
我在objects.about_body
中什么都没得到