【发布时间】:2013-08-02 02:20:47
【问题描述】:
我的 index.html 在 /static/ 文件夹中。当我尝试时,我的 django 应用程序运行正常:
http://127.0.0.1:8000/index.html
但我想通过 url 访问 index.html:
http://127.0.0.1:8000/
我写了一个视图,它可以工作:
class IndexView(TemplateView):
template_name = 'index.html'
我还添加到 urls.py(这让我可以像 http://127.0.0.1:8000/css/style.css 一样提供静态服务):
url(r'^(?P<path>.*)$', 'django.contrib.staticfiles.views.serve', {
'document_root': settings.STATIC_ROOT, 'show_indexes':True
}),
但我认为有一种方法可以在没有 TemplateView 的情况下做我想做的事。
有什么建议吗?谢谢。我的 django 版本是:Django 1.5
编辑:
我将 index.html 放入 static 的原因:我想让 Phonegap 兼容 django 应用程序,所以在正确编码后,我所要做的就是 --> make .zip from static 文件夹和将其作为移动应用程序上传到 Phonegap。简单干净。
【问题讨论】:
-
你为什么不想要一个 TemplateView?就是因为这个原因。
-
我只是觉得有一种方法可以在没有视野的情况下服务。
-
然后使用flatpage app。
-
它是静态 html,而不是模板。没有 django tempalte 标签等的静态代码和平。
-
好的,也许下次我会使用它。将另一个应用程序包含到 django 中并没有更糟糕的页面服务。
标签: django django-views django-staticfiles