Python Django上下文未呈现
我有一个HTML格式的Django模板。我想使用上下文向该模板传递一个变量。但是,当我呈现模板时,Django用模板指定的字符串填充引用该变量的空间。如果设置无效(我测试了该设置) 以下是相关的URLconf:Python Django上下文未呈现,python,django,templates,django-context,Python,Django,Templates,Django Context,我有一个HTML格式的Django模板。我想使用上下文向该模板传递一个变量。但是,当我呈现模板时,Django用模板指定的字符串填充引用该变量的空间。如果设置无效(我测试了该设置) 以下是相关的URLconf: from django.conf.urls import patterns, url from users import views urlpatterns = patterns('', url(r'^$', views.users), url(r'(?P<pk
from django.conf.urls import patterns, url
from users import views
urlpatterns = patterns('',
url(r'^$', views.users),
url(r'(?P<pk>\d+)/$', views.userdetail),
)
我很确定这是由于在指定上下文时出现语法错误造成的,但在看了一个小时后,我找不到一个。如果您认为可能相关,我很乐意发布附加代码。有人能看出我的错误吗
感兴趣人士的模板:
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif%}
<h1> You are viewing the page for the individual user {{ user.name }} </h1>
This user has created the following posts:
{% for post in user.post_list %}
<a href="/posts/{{ post.id }}/">{{ post.title }}</a></li>
{% endfor %}
<p>
Created on {{ user.creation_date }}
</p>
{%if error\u message%}{{{error\u message}{%endif%}
您正在查看单个用户{{user.name}的页面
此用户已创建以下帖子:
{user.post_list%}中的post为%
{%endfor%}
在{user.creation_date}创建
OP写道:
我的主管过来很快就把它修好了。问题是模板有一些预定义的关键字。User是这些关键字中的一个,因此django感到不安,因为我在上下文中传递它{'User':User}
。更改为{'customuser':user}
可避免与django关键字冲突,并修复此问题
我认为您没有呈现正确的
上下文。应该是django.template import Context中的,当我看到关于开头的评论时,我觉得自己像个白痴。我添加了它,但仍然无法正确渲染(完全相同的问题)。我不知道这会不会让我觉得有点傻,但谢谢你的意见。你也能给我们看看你的模板吗?()
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif%}
<h1> You are viewing the page for the individual user {{ user.name }} </h1>
This user has created the following posts:
{% for post in user.post_list %}
<a href="/posts/{{ post.id }}/">{{ post.title }}</a></li>
{% endfor %}
<p>
Created on {{ user.creation_date }}
</p>