在远程机器运行Django开发服务器时不断出现KeyError: 'tried

1 投票
1 回答
908 浏览
提问于 2025-04-15 23:58

我在使用python2.6.1运行django 1.1.1,然后是这样启动django的网页服务器的:

manage.py runserver 192.0.0.1:8000

接着我尝试在另一台电脑上连接这个django开发网页服务器,地址是 http://192.0.0.1:8000/

但是在远程电脑上总是收到这个信息:

Traceback (most recent call last):

  File "C:\Python26\Lib\site-packages\django\core\servers\basehttp.py", line 279, in run
    self.result = application(self.environ, self.start_response)

  File "C:\Python26\Lib\site-packages\django\core\servers\basehttp.py", line 651, in __call__
    return self.application(environ, start_response)

  File "C:\Python26\lib\site-packages\django\core\handlers\wsgi.py", line 241, in __call__
    response = self.get_response(request)

  File "C:\Python26\lib\site-packages\django\core\handlers\base.py", line 115, in get_response
    return debug.technical_404_response(request, e)

  File "C:\Python26\Lib\site-packages\django\views\debug.py", line 247, in technical_404_response
    tried = exception.args[0]['tried']

KeyError: 'tried'

我哪里做错了呢?

如果我在运行django网页服务器的那台电脑上打开 http://192.0.0.1:8000/,就能正常工作,因为那台电脑的ip是192.0.0.1:8000。

1 个回答

2

如果你查看那个文件的修订记录,你会发现 Django 最近开始处理在那个 try 块中出现的 KeyError 错误。

日志信息显示:“确保生成调试用的 404 页面不会引发 KeyError。感谢 pigletto。”

你可以查看这个问题的链接 http://code.djangoproject.com/ticket/12083 和相关的更改记录 http://code.djangoproject.com/changeset/12679

所以,我建议你检查一下是否在生成调试用的 404 页面,或者看看这个问题中的其他评论有没有引起你的注意。

希望这对你有帮助!

更新:在仔细查看代码后,我建议你好好检查一下你的 urls.py 文件,看看在 URL 解析的正则表达式中有没有错误。你是不是在根目录/主页用 url('') 而不是 ('^$')?

撰写回答