1
我想在我的django项目中打开并阅读这个html文件,但是我得到这个 [Errno 2]没有这样的文件或目录:'test.html'。模板文件路径
html = 'test.html'
open_html = open(html, 'r')
soup = BeautifulSoup(open_html, "html5lib")
open_html.close()
但是模板路径似乎做工精细渲染
template = 'test.html'
context = {
}
return render(request, template, context)
TEMPLATES = [
'DIRS': [os.path.join(BASE_DIR, "templates")],
]
我知道我的模板想进入我的应用程序文件夹时,但是我喜欢,让他们在一个文件夹中进行开发时和调试。
'的html =“的test.html” open_html =打开(html,'r')'这段代码并不完整。 html只有文件名test.html,但BeautifulSoup需要完整路径。而不是'html ='test.html''这提供了文件的实际路径。 – ammy