【发布时间】:2016-08-20 13:01:28
【问题描述】:
我正在尝试使用以下方法创建一个重定向到简单静态 .html 文件的 url:
url(r'^impressum/', TemplateView.as_view(template_name='impressum.html'), name='impressum'),
据我了解,template_name 参数采用 .html 文件的位置。我尝试了上述代码的几种变体,尝试重定向到文件,但在加载 localhost:8000/impressum/ 时总是出现 404 错误
这就是我的Folder directory 的样子。我试过“lwc/templates/impressum.html”和“templates/impressum.html”。我在做什么错/这个路径方向是如何工作的
编辑:在我的 TEMPLATE_DIRS 设置下方:
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
【问题讨论】:
-
你试过
r'^impressum/$'吗? -
美元不应该有所作为。但是,添加它是个好主意,否则 url 模式将适用于
/impressum/other-url/以及/impressum/。
标签: django django-templates django-urls