Python 在Django模板中获取共享新闻的良好元数据
我正试图在社交网络上分享我的news.html中的文章。news.html{extend layout.html}但是在:og:title,og:description。。。如果是空的,我怎样才能从用户想要分享的文章中发送好的元数据 这里是my layout.html的标题:Python 在Django模板中获取共享新闻的良好元数据,python,html,django,meta-tags,Python,Html,Django,Meta Tags,我正试图在社交网络上分享我的news.html中的文章。news.html{extend layout.html}但是在:og:title,og:description。。。如果是空的,我怎样才能从用户想要分享的文章中发送好的元数据 这里是my layout.html的标题: {% load static %} {% load compress %} <!DOCTYPE html> <html lang="fr"> <head> &
{% load static %}
{% load compress %}
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'><![endif]-->
<meta name="author" content="YMED SAS">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" href="{% static 'img/favicon.ico' %}">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto+Slab:100,300,400,400italic,700">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,400,500,700,700italic">
{% block extra_head_tags %}
{% endblock %}
</head>
{%load static%}
{%load compress%}
{%block extra_head_tags%}
{%endblock%}
这里是news.html:
{% extends "layout.html" %}
{% load static %}
{% block content %}
<div class="page-title style2 topnews">
<div class="container">
<div class="row">
<div class="col-md-6 col-xs-12">
<h1>
<span class="text-white">Actualités</span>
</h1>
</div>
</div>
</div>
</div>
<div class="page-title">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="breadcrumbs">
<div class="breadcrumb-trail">
<a href="{% url 'homepage' %}">Bienvenue</a><span class="sep">/</span>
Actualités
</div>
</div>
</div><!-- /.col-md-12 -->
</div><!-- /.row -->
</div><!-- /.container -->
</div>
<div class="main-content has-heading">
<div class="container">
{% for new in news %}
<div class="row" id="{{ new.id }}" style="border-bottom:2px solid #000000; padding-top:20px; padding-bottom:20px">
{% if new.photo %}
<div class="col-md-3">
<img src="{{ new.photo.url }}" alt="photo de {{new.photo.title}}"/>
</div>
<div class="col-md-9">
{% else %}
<div class="col-md-12">
{% endif %}
<div id="texte_middle" class="page">
<h3>{{ new.title }}</h3><br>
<h4>{{ new.date_created}}</h4>
<p>{{ new.content|safe }}</p>
<h1>{{ request.build_absolute_uri }}#{{ new.id|add:1 }}</h1>
{% if new.share_button_active %}
{% block extra_head_tags %}
<meta property='og.title' content='{{ new.title }}'/>
<meta property='og.description' content='{{ new.content }}'/>
<meta property='og.image:url' content="https://www.epsmr.org{{new.photo.url}}"/>
<!-- Sharingbutton Facebook -->
<a class="resp-sharing-button__link" href="https://facebook.com/sharer/sharer.php?u={{ request.build_absolute_uri }}%23{{ new.id|add:1 }}" target="_blank" rel="noopener" aria-label="">
<div class="resp-sharing-button resp-sharing-button--facebook resp-sharing-button--small"><div aria-hidden="true" class="resp-sharing-button__icon resp-sharing-button__icon--solidcircle">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M12 0C5.38 0 0 5.38 0 12s5.38 12 12 12 12-5.38 12-12S18.62 0 12 0zm3.6 11.5h-2.1v7h-3v-7h-2v-2h2V8.34c0-1.1.35-2.82 2.65-2.82h2.35v2.3h-1.4c-.25 0-.6.13-.6.66V9.5h2.34l-.24 2z"/></svg>
</div>
</div>
</a>
{% endblock %}
{% endif %}
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}
{%extends“layout.html”%}
{%load static%}
{%block content%}
现实主义
/
现实主义
{%用于新闻中的新内容%}
{%if new.photo%}
{%else%}
{%endif%}
{{new.title}}
{{new.date_created}}
{{new.content | safe}}
{{request.build_absolute_uri}}{{{new.id | add:1}}
{%if new.share\按钮\活动%}
{%block extra_head_tags%}
{%endblock%}
{%endif%}
{%endfor%}
{%endblock%}
如果您需要更多信息,请告诉我。谢谢您的帮助