我正在尝试在视图中获取模板路径。是否有一种动态的方法可以做到这一点,因为目前我正在硬编码路径。
html = 'C:/Users/user/Desktop/project/src/templates/project.html'
模板路径
TEMPLATES = [
'DIRS': [os.path.join(BASE_DIR, "templates")],
]
查看
html = 'C:/Users/user/Desktop/project/src/templates/project.html'
open_html = open(html, 'r')
soup = BeautifulSoup(open_html, "html5lib")
image = soup.find('img', {'name':'image_url'})
img_url = image.get('src')
open_html.close()
app/templates/app/project.html
。 - joshlsullivan