“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。util。同时发生的叉子在游泳池里。常见的并行性准则,用于选择正确的并行度大小   java如何将空白字符追加到指定长度?   安卓应用程序中出现错误,SSLHandshakeException,找不到证书路径的信任锚点   java如何使用JUnit Mockito验证检查方法是否未被调用   java如何使用不同的@RequestMapping解析多个控制器中的静态页面   Selenium中的javascript需要验证搜索结果   访问数据库SQLiteopenHelper方法时java应用程序崩溃(nullpointerexception)   在二叉树中验证最小堆时出现java空指针异常   Java 7的SSL连接失败   java用RestEasyWebTarget替换ProxyFactory不起作用   在Java应用程序中单击“否”按钮后,数组程序冻结(无响应)   数组中的前缀Java初学者前进和   Java HTML解析器,包括脚本标记和LineNumberReader   在java中为长类型数字加前导零   正则表达式无法映射正则表达式java。lang.IllegalArgumentException:模式段中捕获组的数量