我有一个Django
应用程序(我是一个相当新的应用程序,所以我正在尽我最大的努力学习输入和输出),我想让一个url端点简单地重定向到另一个文件夹(应用程序)中的一个静态html文件。
我的项目文件层次结构如下:
docs/
- html/
- index.html
myapp/
- urls.py
我的urls.py
看起来像:
from django.conf.urls import patterns, include, url
from django.views.generic import RedirectView
urlpatterns = patterns('',
url(r'^docs/$', RedirectView.as_view(url='/docs/html/index.html')),
)
但是,当我导航到http://localhost:8000/docs
时,我看到浏览器重定向到http://localhost:8000/docs/html/index.html
,但是页面不可访问。
是否有任何原因使/docs/html/index.html
在这样的重定向中不可用于myApp
应用程序?
一个指针将非常感谢。
我想你想要的是一个Template View,而不是一个重定向视图。你可以这样做:
url.py
只要确保指向
index.html
的路径在TEMPLATE DIRS设置中,或者将其放在应用程序的templates
文件夹中(This answer可能有帮助)。我敢肯定Django正在寻找一个与
/docs/html/index.html
匹配的URL路由,它不知道服务一个静态文件,当它找不到路由时,它显示一个错误相关问题 更多 >
编程相关推荐