首页 > 解决方案 > 无法使用 Django 重定向流量

问题描述

我正在尝试使用djangae仅提供静态文件。此外,我想将所有流量路由到index.html. 当我访问http://localhost:8000时,我收到 500 错误。当我访问http://localhost:8000/static/index.html时,我得到了正确的文件。

我究竟做错了什么?

urlpatterns的如下:

...
from . import views
...
urlpatterns = (
    ...

    url(r'^', views.home),
)

我已经尝试过r'^$'r'^.*$''',但我没有得到任何不同的结果。

视图.py

from django.shortcuts import redirect

def home(request):
    return redirect('/static/index.html', permanent=True)

500 错误

  File "/usr/lib/python2.7/site-packages/pytz/__init__.py", line 493, in <module>
    for l in open(os.path.join(_tzinfo_dir, 'zone.tab'))
  File "/git_repos/djangae/proj/sitepackages/dev/google_appengine/google/appengine/tools/devappserver2/python/stubs.py", line 260, in __init__
    raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: '/usr/share/zoneinfo/zone.tab'

标签: pythondjangodjangae

解决方案


我发现了在这个特定方面的解决方法。我将zone.tab文件移动到<project_name>/并编辑了我的 app.yaml 以包含此环境变量:PYTZ_TZDATADIR: <project_name>.

仍然不确定为什么需要在路由完成之前调用 pytz。


推荐阅读