模板渲染期间出错/无法解析某些字符

问题描述

在尝试运行服务器并转到帐户/配置文件y时,我试图获取每个配置文件的个人信息,

无法解析某些字符:|%with website = profile.website | |认值:“”%

{% extends 'base.html' %}

{% block title %}Profile{% endblock %}

{% block content %}

<h1>
    {{ user.get_null_name }} (@{{ user.username }})
</h1>
 
{% with profile=user.profile %}
    {% if profile %}
        <h2>
            {{ profile.persona }}  
        </h2>
        <div> 
            {{ profile.bio|default:"" }}
        </div>
        <div>
            {{ % with website=profile.website | default:"" % }}
                <a href="{{website}}">{{website}} </a>
            {% endwith %}
        </div>
        <br/>
        <div>
            Interest:
            {% for Interest in profile.interest.all %}
                <span>
                    {{ interest.name }}{% if not forloop.last %},{% endif %}
                </span>
            {% endfor %}
        </div>
    {% endif %}
{% endwith %}


{% endblock %}

解决方法

模板标签使用双大括号( {{ … }} ),但使用单个大括号,%紧跟其后(因此{% … %})。模板中的{% with … %}块使用双大括号:

{% with website=profile.website|default:'' %}
    …
{% endwith %}