擅长:python、mysql、java
<blockquote>
<p>NOTE: <code>direct_to_template</code> has been deprecated since Django 1.5. Use
<a href="https://stackoverflow.com/questions/15621048/how-can-i-satisfy-an-import-of-direct-to-template">TemplateView.as_view</a> instead.</p>
</blockquote>
<p>我想你想要的是一个<a href="https://docs.djangoproject.com/en/1.4/topics/generic-views/#using-generic-views" rel="nofollow noreferrer">Template View</a>,而不是一个重定向视图。你可以这样做:</p>
<p><strong>url.py</strong></p>
<pre><code>from django.conf.urls import patterns, include, url
from django.views.generic.simple import direct_to_template
urlpatterns = patterns('',
(r'^docs/$', direct_to_template, {
'template': 'index.html'
}),
)
</code></pre>
<p>只要确保指向<code>index.html</code>的路径在TEMPLATE DIRS设置中,或者将其放在应用程序的<code>templates</code>文件夹中(<a href="https://stackoverflow.com/a/15411829/345290">This answer</a>可能有帮助)。</p>