2017-01-25 8 views
0

私はブログサイトを構築するためにDjangoを使用しています。私はプロジェクトでテンプレートを拡張することができません。Djangoと拡張テンプレートは機能しませんか?

私は2つのテンプレートがあります。

  1. base.html
  2. post.html

Base.htmlは私の親テンプレートとpost.htmlはbase.htmlを拡張し、私の子テンプレートです。

私は、Djangoはpost.htmlを拡張するために取得することができません。私は、Webサーバーのbase.htmlの表示を実行するが、そこにpost.htmlからテキストがありません。

テンプレートに関するDjangoのドキュメントと拡張方法を読んだことがありますが、正しい構文が必要だと思いますが、その理由は分かりません。

私はこのプロジェクトでもBoostrapを使用しています。

はあなたの助けをありがとう、 Nermin

post.html

{% extends "post/base.html" %} 

{% block content %} 
    <div class="blog-post"> 
      <h2 class="blog-post-title">Sample blog post</h2> 
      <p class="blog-post-meta">January 1, 2014 by <a href="#">Mark</a></p> 

      <p>Blog text goes here.</p> 


    </div><!-- /.blog-post --> 
{% endblock %} 

は、私は解決策を見つけたコードここ

base.html

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 
    <link rel="icon" href="../../favicon.ico"> 

    <!-- load static files --> 
    {% load staticfiles %} 

    <title>Blog Title</title> 

    <!-- Bootstrap core CSS --> 
    <link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet"> 

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> 
    <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> 

    <!-- Custom styles for this template --> 
    <link href="{% static 'css/blog.css' %}" rel="stylesheet"> 

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! --> 
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> 
    <script src="../../assets/js/ie-emulation-modes-warning.js"></script> 

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 
    <!--[if lt IE 9]> 
     <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> 
     <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 
    <![endif]--> 
    </head> 

    <body> 

    <div class="blog-masthead"> 
     <div class="container"> 
     <nav class="blog-nav"> 
      <a class="blog-nav-item active" href="#">Home</a> 
      <a class="blog-nav-item" href="#">About</a> 
     </nav> 
     </div> 
    </div> 

    <!-- blog post goes here --> 

    {% block content %} 
    {% endblock %} 


    <div class="container"> 

     <div class="blog-header"> 
     <h1 class="blog-title">Code'N Cofee Blog</h1> 
     <p class="lead blog-description">Live and write code. </p> 
     </div> 

     <div class="row"> 

     <div class="col-sm-8 blog-main"> 


      <nav> 
      <ul class="pager"> 
       <li><a href="#">Previous</a></li> 
       <li><a href="#">Next</a></li> 
      </ul> 
      </nav> 

     </div><!-- /.blog-main --> 

     <div class="col-sm-3 col-sm-offset-1 blog-sidebar"> 
      <div class="sidebar-module sidebar-module-inset"> 
      <h4>About</h4> 
      <p>Etiam porta <em>sem malesuada magna</em> mollis euismod. Cras mattis consectetur purus sit amet fermentum. Aenean lacinia bibendum nulla sed consectetur.</p> 
      </div> 
      <div class="sidebar-module"> 
      <h4>Archives</h4> 
      <ol class="list-unstyled"> 
       <li><a href="#">March 2014</a></li> 
       <li><a href="#">February 2014</a></li> 
       <li><a href="#">January 2014</a></li> 
       <li><a href="#">December 2013</a></li> 
       <li><a href="#">November 2013</a></li> 
       <li><a href="#">October 2013</a></li> 
       <li><a href="#">September 2013</a></li> 
       <li><a href="#">August 2013</a></li> 
       <li><a href="#">July 2013</a></li> 
       <li><a href="#">June 2013</a></li> 
       <li><a href="#">May 2013</a></li> 
       <li><a href="#">April 2013</a></li> 
      </ol> 
      </div> 
      <div class="sidebar-module"> 
      <h4>Elsewhere</h4> 
      <ol class="list-unstyled"> 
       <li><a href="#">GitHub</a></li> 
       <li><a href="#">Twitter</a></li> 
       <li><a href="#">Facebook</a></li> 
      </ol> 
      </div> 
     </div><!-- /.blog-sidebar --> 

     </div><!-- /.row --> 

    </div><!-- /.container --> 

    <footer class="blog-footer"> 
     <p>Blog template built for <a href="http://getbootstrap.com">Bootstrap</a> by <a href="https://twitter.com/mdo">@mdo</a>.</p> 
     <p> 
     <a href="#">Back to top</a> 
     </p> 
    </footer> 


    <!-- Bootstrap core JavaScript 
    ================================================== --> 
    <!-- Placed at the end of the document so the pages load faster --> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
    <script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script> 
    <script src="../../dist/js/bootstrap.min.js"></script> 
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> 
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script> 
    </body> 
</html> 

答えて

0

を入力してください。問題は2つのhtmlファイルではなく、私のviews.pyファイルにあります。基本的に私のインデックス機能では、views.pyはレンダリングされていたので、何も表示されませんでした。post.html

post.htmlがbase.htmlを拡張しているとすれば、 post.htmlを以下のようにレンダリングすると、コードが修正されます。

これは、これが似たような問題を抱えている人に役立つことを期待しています。

これは私の指数関数はviews.py

from django.shortcuts import render 
from django.http import HttpResponse 


def index(request): 
    return render(request, 'post/post.html', {'': ''}) 
になりました見え方であります
関連する問題