【发布时间】:2011-01-23 23:35:16
【问题描述】:
我有一个网络应用程序,用户可以在其中拥有个人资料(有点像 facebook),他们可以查看自己的个人资料以及其他人的个人资料。您在自己的个人资料中看到的将是所有内容,但查看您个人资料的其他人可能无法看到其中的所有内容。
为了做到这一点,我有 common-profile.html 和 profile.html 其中 profile.html 包括 common-profile.html 和 common-profile.html 是每个人都可以看到的。因此,如果我想查看自己的个人资料,我会看到 profile.html,但其他人会看到 common-profile.html。
问题是,当我使用模板继承时,这两个模板都继承自某个基本模板,因此模板会被导入两次。
profile.html:
{% extends 'base.html' %}
{% block content %}
{% include 'common-profile.html' %}
...other stuff would go here
{% endblock %}
common-profile.html:
{% extends 'base.html' %}
{% block content %}
<h1>{{c_user.first_name}} {{c_user.last_name}}<h1>
...other stuff would go here
{% endblock %}
这只是个坏主意吗?我应该只有一个配置文件并检查权限/在模板标签中使用一些 if 语句吗?我不想在我的 html 页面中包含太多逻辑,但如果只是一些 if 语句来决定显示什么,也许没关系?
【问题讨论】: