【发布时间】:2017-07-04 02:18:08
【问题描述】:
所以我试图在我的视图中获取模板路径。是否有这样做的动态方式,因为目前我正在硬编码路径。
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()
【问题讨论】:
-
Django 的美妙之处在于它会根据文件夹结构自动发现您的模板文件 -
app/templates/app/project.html。
标签: django django-views