Django模板无法正确呈现

时间:2015-02-02 07:29:03

标签: python django django-templates django-views

app.views.py

from django.shortcuts import render
from django.views.generic import View

        class RegisterView(View):
            def get(self,request):
                return render(request, 'register.html' , { 'title' : 'Register Page'} );

register.html

{% extends 'base.html' }

{% block head}
    {{title}}

{% endblock}


{% block content} 

    Register Page

{% endblock }

base.html                                     竞技场应用             {%block head}                 主页             {%endblock}

    </title>
</head>
<body>
<h2> Welcome to arena app </h2>
    {% block  content }

    <p>
        this is base page
    </p>

    {% endblock  }

</body>

</html>

**问题:**当我访问http://127.0.0.1:8000/account/register时,这就是我得到的:

http://i.stack.imgur.com/Y9Lod.png

我的文件结构:

http://i.stack.imgur.com/1KvDP.png

最后我TEMPLATE_DIRS settings.py的{​​{1}}变体如下:

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = (

    os.path.join(BASE_DIR, 'templates'),
 )

Django版本:1.7.3

1 个答案:

答案 0 :(得分:0)

代码未正确转义。应以{%%}开头和结尾
示例:

{% endblock %}

{% endblock}