'tweet this'和'share on facebook'的模板标签
项目描述
提供以下模板标签:
‘Tweet This’
‘在Facebook上分享’
‘在Google+上分享’
‘在LinkedIn上分享’
‘在Telegram上分享’
‘在WhatsApp上分享’
‘mailto://’.
‘保存到Pinterest’
‘复制到剪贴板’
提供纯HTML 模板以供方便使用,但您可以覆盖它们以提供自己的外观和感觉。
安装
$ python -m pip install django-social-share
将应用程序添加到INSTALLED_APPS
INSTALLED_APPS += ['django_social_share']
您还必须将django.template.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', ], } }, ]
注意,在大多数情况下,如果您使用localhost或您的域名无法从公共互联网访问,则共享功能可能无法正常工作。对于本地开发测试,您可以使用ngrok等服务,并将您的Site实例的domain设置为ngrok提供的主机名。
用法
{% post_to_facebook <object_or_url> <link_text> <link_class> %} {% post_to_gplus <object_or_url> <link_text> <link_class> %} {% post_to_twitter <text_to_post> <object_or_url> <link_text> <link_class> %} {% post_to_linkedin <object_or_url> <link_class> %} {% send_email <subject> <text_to_post> <object_or_url> <link_text> <link_class> %} {% post_to_reddit <text_to_post> <object_or_url> <link_text> <link_class> %} {% post_to_telegram <text_to_post> <object_or_url> <link_text> <link_class> %} {% post_to_whatsapp <object_or_url> <link_text> <link_class> %} {% save_to_pinterest <object_or_url> <link_class> %} {% add_pinterest_script %} {% copy_to_clipboard <object_or_url> <link_text> <link_class> %} {% add_copy_script %}
<text_to_post>可以包含任何有效的Django模板代码。请注意,Facebook不再支持此功能。
<object_or_url>是可选的(除了Telegram)。如果您传递一个Django模型实例,它将使用其get_absolute_url方法。另外,如果您已安装django_bitly,它将使用Twitter上的其短链接。
<link_text>也是可选的。它定义了用于元素的文本。默认为“发布到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。
{% 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变量,包含Telegram分享弹出窗口的URL。
{% post_to_whatsapp_url <object_or_url> %}
将在上下文中添加一个whatsapp_url变量,包含WhatsApp分享的URL。
{% save_to_pinterest_url <object_or_url> %}
将在上下文中添加一个pinterest_url变量,包含Pinterest分享的URL。
{% copy_to_clipboard <object_or_url> <link_text> <link_class> %}
将在上下文中添加一个copy_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_or_url %} {% 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> %} {% post_to_whatsapp object_or_url "Share via WhatsApp" %} {% save_to_pinterest object_or_url %} {% add_pinterest_script %} // Required for save_to_pinterest. Add to the end of body tag. {% copy_to_clipboard object_or_url "Copy to clipboard!" %} {% add_copy_script %} // Required for copy_to_clipboard. Add to the end of body tag.
模板
模板位于
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.
django_social_share/templatetags/post_to_whatsapp.html.
django_social_share/templatetags/save_to_pinterest.html.
django_social_share/templatetags/pinterest_script.html.
django_social_share/templatetags/copy_to_clipboard.html.
django_social_share/templatetags/copy_script.html.
您可以根据需要覆盖它们。
问题
如果您有任何问题,请使用GitHub的问题。请勿给作者发邮件。
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源代码分布
构建分布
哈希值 对于 django_social_share-2.3.0-py2.py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 13d0a1fbb2a90e3a6e7eb556315ececd1e93a906574a3284affbe2f43e2f7398 |
|
MD5 | 6bf1edfea8f9e347f5c3f27f8ee80ccf |
|
BLAKE2b-256 | be8cfab0089cb1f161435d082d9ee5945d8d2a678da15be8bda5181e6aa4de60 |