擅长:python、mysql、java
<p><code>render</code>逻辑不同,这取决于传递给<code>render</code>的内容:</p>
<pre><code>def render(self, context):
"Display stage can be called many times"
with context.render_context.push_state(self):
if context.template is None:
with context.bind_template(self):
context.template_name = self.name
return self._render(context)
else:
return self._render(context)
</code></pre>
<p>看起来您可以将参数<code>template_name</code>更改为<code>name</code>,但是您的对象没有{<cd5>}值,这就是为什么创建和使用<code>Context</code>的实例会更好</p>
<p><a href="https://docs.djangoproject.com/en/1.11/_modules/django/template/base/#Template.render" rel="nofollow noreferrer">https://docs.djangoproject.com/en/1.11/_modules/django/template/base/#Template.render</a></p>
<p>文档显示传递<code>Context</code>的实际实例,因此我建议您在代码中这样做,而不是仅仅传递dict:</p>
^{pr2}$
<p>因此,修复代码的最简单方法如下:</p>
<pre><code>from django.template import Context
...
return render(request=request, template_name="mytemplate.html", context=Context({"form": form, "update": updateType}))
</code></pre>