from django.conf import settings
def myview(request):
settings.TEMPLATE_STRING_IF_INVALID = '%s' # '%s' will get expanded to the variable name that was not found
...
template = render(request, 'myview.html', {})
settings.TEMPLATE_STRING_IF_INVALID = ''
return template
请注意这很难看。如果在将模板“如果无效”重置回“”之前,其他用户在短时间内请求了其他页面,则他们可能会看到显示的标记无效。Django docs say specifically NOT to do this,但也有一个open ticket,表明它可能在某些设置中是可以的。在
希望有更聪明的人能来给我们一个更好的解决方案。在
相关问题 更多 >
编程相关推荐