python - 无法使用 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'
解决方案
我发现了在这个特定方面的解决方法。我将zone.tab
文件移动到<project_name>/
并编辑了我的 app.yaml 以包含此环境变量:PYTZ_TZDATADIR: <project_name>
.
仍然不确定为什么需要在路由完成之前调用 pytz。
推荐阅读
- sql - 从审计表中选择旧值/新值
- android - 如何检测特定应用是否可以展示广告
- .net - 我正在尝试使用 Windows 身份验证从我的 Azure 函数连接 SQL Server(本地)
- reactjs - 如何基于现有的 React 组件创建 jupyter 扩展
- linux - 如何制作类似 /proc 的文件
- angular - 订阅主题连续接收多次
- opengl - 计算着色器图像和原子一致性
- ios - 过渡动画不工作 Swift 5
- excel - 为什么 Replace(x,Chr(160)) 替换 Empty Space AND comma 而不是 Empty Space
- node.js - 如何在 Elastic Beanstalk 上启用安全 Web 套接字