我计划在博客网站中创建一个页面,根据页面浏览量排列和显示所有博客文章。不知道如何实现它。
模型.py
class BlogPost(Page):
date = models.DateField(verbose_name="Post date")
categories = ParentalManyToManyField("blog.BlogCategory", blank=True)
tags = ClusterTaggableManager(through="blog.BlogPageTag", blank=True)
body = RichTextField(blank=False)
main_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=False,
on_delete=models.SET_NULL,
related_name='+')
def get_context(self, request, *args, **kwargs):
context = super().get_context(request, *args, **kwargs)
blogposts = self.get_siblings().live().public().order_by('-first_published_at')
context['blogposts'] = blogposts
return context
content_panels = Page.content_panels + [
FieldPanel('date'),
FieldPanel('categories', widget=forms.CheckboxSelectMultiple),
FieldPanel('tags'),
ImageChooserPanel('main_image'),
FieldPanel('body', classname="full"),
]
Run Code Online (Sandbox Code Playgroud) 不要在本地下载字体并将其链接到 ImageFont.truetyp() ,如下所示:
from pillow import ImageFont
font = ImageFont.truetype('Roboto-Regular.ttf', size=10)
Run Code Online (Sandbox Code Playgroud)
我可以做这样的事情吗:
from pillow import ImageFont
font = ImageFont.truetype('https://github.com/googlefonts/roboto/blob/master/src/hinted/Roboto-Regular.ttf', size=10)
Run Code Online (Sandbox Code Playgroud)