2012-10-23 23 views
-1

我有一個簡單的urls.py文件:如何在django例子中獲取index.html?

(r'^(.*.html)$','django.views.static.serve', {'document_root': ROOT + '/media/html/'}) 

如何獲得index.html文件的網址:HTTP:/myserver.com/?

+0

按照[Django的教程](https://docs.djangoproject.com/en/1.4/intro/tutorial03/ #寫的看法,認爲,實際上-DO-東西) –

回答

2

urls.py

from django.views.generic.simple import direct_to_template 

urlpatterns = patterns('', 
    (r'^$', direct_to_template, {'template': 'index.html'}),  
) 

我假設你想有一個靜態重定向到index.html試試這個。所以這就是它。

如果你想添加動態內容,那麼你需要在views.py中添加一個方法。

1

在Django中1.3+,您還可以使用基於類的通用視圖:

from django.views.generic.base import TemplateView 

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