我已按照所有步骤安装和使用django-social-share。当我在要显示的详细信息页面上加载social_share时,使用默认模板可以正常工作。当我尝试覆盖默认模板时,没有显示任何内容。我在root_dir / templates / templatetags / post_to_facebook.html中有模板。我不知道为什么在尝试使用这些自定义模板时什么都没显示-自定义模板和默认模板都没有显示。任何帮助将不胜感激。
[这是我的文件settings.py
INSTALLED_APPS = [
# Local apps
'users.apps.UsersConfig',
'pages.apps.PagesConfig',
'blog.apps.BlogConfig',
# Third party
'django_social_share',
'crispy_forms',
.
.
.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
.
.
.
post_to_facebook.html
<span class="w3-badge w3-hover-blue facebook-this">
<a href="{{ facebook_url }}" class="w3-xlarge" target="_blank" title="Share on Facebook"><i class="fa fa-facebook"></i></a>
</span>
post_to_twitter.html
<span class="w3-badge w3-hover-blue tweet-this">
<a href="{{ tweet_url }}" class="w3-xlarge meta-act-link meta-tweet" target="_blank" title="Share on Twitter"><i class="fa fa-twitter"></i></a>
</span>
post_detail.html
{% extends 'base.html' %}
{% load social_share %}
{% load static %}
{% block title %} {{ post.title }} {% endblock title %}
{% block content %}
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
<h1>{{ post.title }}</h1>
<p class="date">Published {{ post.publish }} by {{ post.author }}
</p>
{{ post.body|linebreaks }}
<p><a href="{% url 'post_edit' post.pk post.slug %}">Edit</a> |
<a href="{% url 'post_delete' post.pk post.slug %}">Delete</a></p>
<p>Back to <a href="{% url 'post_list' %}">Forum</a>.</p>
{% post_to_twitter post.title post %}
{% post_to_facebook post %}
似乎您正在设置html模板的样式。文件路径应为root_dir / templates / django_social_share / templatetags / post_to_facebook.html。