显示简单的HTML页面DJango

我目前正在使用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中添加什么才能真正实现index.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
最佳答案
urls.py

from django.conf.urls import patterns,url
from app_name.views import *

urlpatterns = patterns('',url(r'^$',IndexView.as_view()),)

views.py

from django.views.generic import TemplateView

class IndexView(TemplateView):
    template_name = 'index.html'

根据@Ezequiel Bertti的回答,删除应用

from django.conf.urls import patterns
from django.views.generic import TemplateView

urlpatterns = patterns('',(r'^index.html',TemplateView.as_view(template_name="index.html")),)

您的index.html必须存储在模板文件夹中

webapp/
    myapp/
        __init__.py
        models.py
        tests.py
        views.py
        templates/      <---add
            index.html  <---add
    manage.py
    project/
        __init__.py
        settings.py
        templates/      <---remove
            index.html  <---remove
        urls.py
        wsgi.py

相关文章

HTML代码中要想改变字体颜色,常常需要使用CSS样式表。CSS是...
HTML代码如何让字体盖住图片呢?需要使用CSS的position属性及...
HTML代码字体设置 在HTML中,我们可以使用标签来设置网页中的...
在网页设计中,HTML代码的字体和字号选择是非常重要的一个环...
HTML(Hypertext Markup Language,超文本标记语言)是一种用...
外链是指在一个网页中添加一个指向其他网站的链接,用户可以...