【发布时间】:2013-03-18 10:38:39
【问题描述】:
我目前正在使用 Django 1.5,但不知道如何显示一个简单的 html 页面。我一直在阅读有关基于类的视图,但不确定这是我想要做的。
我正在尝试显示一个简单的 index.html 页面,但根据我看到的一些示例,我需要将此代码放在 app/views.py 中:
def index(request):
template = loader.get_template("app/index.html")
return HttpResponse(template.render)
为什么我的 index.html 页面必须与与我的 django 项目关联的应用程序相关联?对我来说,将 index.html 页面与整个项目对应起来似乎更有意义。
更重要的是,在我的 views.py 文件中使用此代码,我需要在我的 urls.py 中放入什么才能真正索引.html?
编辑:
Django 项目结构:
webapp/
myapp/
__init__.py
models.py
tests.py
views.py
manage.py
project/
__init__.py
settings.py
templates/
index.html
urls.py
wsgi.py
【问题讨论】:
-
阅读 django 教程会更有帮助。