wagtail_hooks.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:wagtail-sharing 作者: cfpb 项目源码 文件源码
def add_sharing_banner(page, response):
    if not getattr(settings, 'WAGTAILSHARING_BANNER', True):
        return

    if hasattr(response, 'render') and callable(response.render):
        response.render()

    html = force_text(response.content)
    body = re.search(r'(?i)<body.*?>', html)

    if body:
        endpos = body.end()

        banner_template_name = 'wagtailsharing/banner.html'
        banner_template = loader.get_template(banner_template_name)

        banner_html = banner_template.render()
        banner_html = force_text(banner_html)

        content_with_banner = html[:endpos] + banner_html + html[endpos:]
        response.content = content_with_banner
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号