【问题标题】:Django Template not rendering correctlyDjango 模板未正确呈现
【发布时间】:2015-04-01 02:44:34
【问题描述】:

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 竞技场应用 {% 块头} 主页 {% 端块 }

    </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

最后我在settings.py 中的TEMPLATE_DIRS var 看起来像:

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

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

Django 版本:1.7.3

【问题讨论】:

  • 您在所有标签中都缺少% 这样的% }

标签: python django django-templates django-views


【解决方案1】:

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

{% endblock %}

不是

{% endblock}

【讨论】:

    猜你喜欢
    • 2020-09-06
    • 2011-09-01
    • 2015-06-18
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    • 2015-08-22
    • 1970-01-01
    • 2012-03-23
    相关资源
    最近更新 更多