Django模板中的Opengraph标签(og:标签)未被Facebook

时间:2018-02-07 23:00:55

标签: python django templates facebook-graph-api opengraph

我一直试图让我的django网站上的opengraph标签正常工作。我使用" www.somewebsite.com"在此问题中作为网站网址。我在标题中使用了以下静态代码:

<meta property="og:title" content="websitename" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://www.somewebsite.com/" />
<meta property="og:description" content="Some description."/>
<meta property="og:image" content="https://www.somewebsite.com/static/image.png" />

这不起作用,所以我安装了django-meta(http://django-meta.readthedocs.io/en/latest/installation.html)并在我的目标网页视图中实现了以下代码,因此元数据会在服务器上动态添加:

# basic page view
class BasicView(View):
    template_name = 'landing/landing.html'

    # get request
    def get(self, request):
        context = {
            "meta": Meta(
               title="Websitename",
               description='Some description.',
               type='website',
               url='https://www.somewebsite.com/', 
               image='https://www.somewebsite.com/static/image.png',
               use_title_tag=True,
               use_facebook=True,
               use_og=True,
            ),
         }

         return render(request, self.template_name, context)

使用以下模板:

<head {% meta_namespaces %}>
    {% include 'meta/meta.html' %}
</head>

这导致:

<head  prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#">
   <meta name="description" content="Some description.">
   <title>Websitename</title>
   <meta property="og:title" content="Websitename">
   <meta property="og:url" content="https://www.somewebsite.com/">
   <meta property="og:description" content="The easiest way of making digital music.">
   <meta property="og:image" content="https://www.judgemysound.com/static/image.png">
</head>

在Facebook调试工具(https://developers.facebook.com/tools/debug/og/object/)中获取新的刮擦信息时,它会提供以下信息(图片):

Meta data scraped from my website with facebook sharing debugger

奇怪的是;我的og标签中的信息不会被Facebook删除。有谁知道我怎么能用og:标签在Facebook上用Django应用程序工作?

谢谢!

0 个答案:

没有答案