我正在使用 Django,我需要从给定的模板 (lab.html) 动态生成一个 HTML 文件:
from django.template import Template, Context
from django.conf import settings
settings.configure()
f = qc.QFile('lab.html')
f.open(qc.QFile.ReadOnly | qc.QFile.Text)
stream = qc.QTextStream(f)
template = stream.readAll()
print(template)
f.close()
t = Template(template)
c = Context({"result": "test"}) #result is the variable in the html file that I am trying to replace
Run Code Online (Sandbox Code Playgroud)
但是,我不断收到这个奇怪的错误,经过一些研究,我在任何地方都找不到。有什么想法吗?
Traceback (most recent call last):
File "/Users/gustavorangel/PycharmProjects/help/HelpUI.py", line 262, in filesSearch
t = Template(template)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/template/base.py", line 184, in __init__
engine = Engine.get_default()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/template/engine.py", line 83, in …Run Code Online (Sandbox Code Playgroud)