2017-08-14 4 views
0

プロジェクトについては、フォーラムのような基本的なウェブサイトを構築しようとしています。しかし、我々は1の代わりに、複数のページに投稿しようとしていると、別のポストは、そのページに追加することを可能にする部分に拡張を追加することはできません。djangoを使用して複数のページに投稿する方法

{% extends 'blog/base.html' %} 
 

 
{% block content %} 
 
    <div class="post"> 
 
     {% if post.published_date %} 
 
      <div class="date"> 
 
       {{ post.published_date }} 
 
      </div> 
 
     {% endif %} 
 
     {% if user.is_authenticated %} 
 
    <a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-pencil"></span></a> 
 
{% endif %} 
 
     <h1>{{ post.title }}</h1> 
 
     <p>{{ post.text|linebreaksbr }}</p> 
 
    </div> 
 
{% endblock %}

どのような方法にはあります別の方法で複数のページにこれらの投稿を表示させますか?

答えて

0

"include"キーワードについて質問していると思いますか?と "with"テンプレートタグ?

post_template.html

<div class="post"> 
     {% if post.published_date %} 
      <div class="date"> 
       {{ post.published_date }} 
      </div> 
     {% endif %} 
     {% if user.is_authenticated %} 
    <a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-pencil"></span></a> 
{% endif %} 
     <h1>{{ post.title }}</h1> 
     <p>{{ post.text|linebreaksbr }}</p> 
    </div> 

{% extends "base.html" %} 
{% with some_post as post %}{% include "post_template.html"%} {% endwith %} 

other_page.html some_page.html

{% extends "base.html" %} 
{% with some_other_post as post %}{% include "post_template.html"%} {% endwith %} 
+0

どのファイル私が代わりにリンクしますsome_postプレースホルダ? – ctug

0

WHEあなたはポストは、あなたがdictsのリストを渡していると仮定すると、表示したいreverはpostsと呼ばれる:templates/post.html

{% for post in posts %} 
    {% include 'templates/post.html' %} 
{% endfor %} 

<div class="post"> 
    {% if post.published_date %} 
     <div class="date"> 
      {{ post.published_date }} 
     </div> 
    {% endif %} 
    {% if user.is_authenticated %} 
    <a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}"><span class="glyphicon glyphicon-pencil"></span></a> 
    {% endif %} 
    <h1>{{ post.title }}</h1> 
    <p>{{ post.text|linebreaksbr }}</p> 
</div> 

参照:How do you insert a template into another template?

関連する問題