“tweet this”和“share on facebook”的模板标记

django-social-share的Python项目详细描述


https://travis-ci.org/fcurella/django-social-share.svg?branch=masterhttps://coveralls.io/repos/github/fcurella/django-social-share/badge.svg?branch=master

为以下对象提供模板标记: *'推特这个' *'在Facebook上共享此' *'在Google+上共享' *'在LinkedIn上共享' *'电报共享' *“mailto://”。

纯html templates是为了您的方便而提供的,但是您可以重写它们以提供您自己的外观。

安装

$ pip install django-social-share

将应用程序添加到INSTALLED_APPS

INSTALLED_APPS += ['django_social_share']

您还必须将django.core.context_processors.request添加到context_processors列表中。这样,模板标记将使用正确的方案和主机名:

TEMPLATES=[
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
        ],
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.request',
            ],
        }
    },
]

用法

{% post_to_facebook <object_or_url> <link_text> %}

{% post_to_gplus <object_or_url> <link_text> %}

{% post_to_twitter <text_to_post> <object_or_url> <link_text> %}

{% post_to_linkedin <subject> <object_or_url> <link_text> %}

{% post_to_mail <email_subject> <text_to_post> <object_or_url> <link_text> %}

{% send_email <subject> <text_to_post> <object_or_url> <link_text> %}

{% post_to_reddit <text_to_post> <object_or_url> <link_text> %}

{% post_to_telegram <text_to_post> <object_or_url> <link_text> %}

<text_to_post>可以包含任何有效的django模板代码。请注意,Facebook不再支持这一点。

<object_or_url>是可选的(电报除外)。如果您传递一个django模型实例,它将使用其get_absolute_url方法。另外,如果您安装了django_bitly,它将在twitter上使用它的shorturl。

<link_text>也是可选的。它定义了用于a元素的文本。默认为“发布到Facebook”和“发布到Twitter”。

<subject>可以包含任何有效的django模板代码。

{% post_to_twitter_url <text_to_post> <object_or_url> %}

将向上下文中添加一个tweet_url变量,其中包含Twitter共享器弹出窗口的URL。

{% post_to_facebook_url <object_or_url> %}

将向上下文中添加一个facebook_url变量,其中包含Facebook共享器弹出窗口的URL。

{% post_to_gplus_url <object_or_url> %}

将向上下文中添加一个gplus_url变量,其中包含Google+共享器弹出窗口的URL。

{% post_to_linkedin_url <subject> <object_or_url> %}

将向上下文中添加一个linkedin_url变量,其中包含LinkedIn共享器弹出窗口的URL。

{% send_email_url <subject> <text_to_post> <object_or_url> <link_text> %}

将向上下文中添加一个mailto_url变量,其中包含mailto锚的url。

{% post_to_reddit_url <text> <object_or_url> %}

将向上下文中添加一个reddit_url变量,其中包含reddit海报页的url。

{% post_to_telegram <text> <object_or_url> %}

将向上下文中添加一个telegram_url变量,其中包含电报共享器弹出窗口的url。

示例:

{% load social_share %}

{% post_to_facebook object_or_url "Post to Facebook!" %}
{% post_to_twitter "New Song: {{object.title}}. Check it out!" object_or_url "Post to Twitter" %}
{% post_to_gplus object_or_url "Post to Google+!" %}
{% post_to_linkedin object.title object_or_url "Post to LinkedIn" %}
{% send_email object.title "New Song: {{object.title}}. Check it out!" object_or_url "Share via email" %}
{% post_to_reddit "New Song: {{object.title}}" <object_or_url> %}
{% post_to_telegram "New Song: {{object.title}}" <object_or_url> %}

模板

模板位于:

  • django_social_share/templatetags/post_to_twitter.html
  • django_social_share/templatetags/post_to_facebook.html
  • django_social_share/templatetags/post_to_gplus.html
  • django_social_share/templatetags/send_email.html
  • django_social_share/templatetags/post_to_linkedin.html
  • django_social_share/templatetags/post_to_reddit.html
  • django_social_share/templatetags/post_to_telegram.html

你可以超越它们以适应你的里程数。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何使用for循环从字符数组中绘制精灵   对象关系的java空接口建模   java在使用片段时无法启动activity ComponentInfo   java获得网络适配器的最大带宽   JavaJSP:如何从会话中获取价值?   时间复杂性就性能而言,在Java中,使用多个操作执行一个for或使用每个操作执行多个for会产生什么影响?   Java Scanner在使用NetBeans时出现问题,它不会显示任何反应   java如何在char变量中存储换行符?   java Apache Pivot和自定义ListView ItemRenderer   音频Java按钮无声音播放   Java向Hashmaps数组添加元素会产生空错误   java运行一个处理类的对象   目标语言为Java的PL/SQL代码生成ANTLR解析器   java在片段上实现向上导航   java Eclipse IDE和Spring工具套件的SQL开发工具在哪里?为什么在他们的市场上似乎找不到它们?   使用EventHandler更改java图形   java在springboot中将protobuf作为JSON发送   oraclesqldeveloperjava。sql。SQLRecoverableException:IO错误:生成NL异常