“tweet this”和“share on facebook”的模板标记
django-social-share的Python项目详细描述
为以下对象提供模板标记: *'推特这个' *'在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。
你可以超越它们以适应你的里程数。