难以理解的Django Runserver错误

时间:2011-11-02 00:05:30

标签: python django

我在Django遇到了很多问题(并非所有问题都解决了),但这是迄今为止最奇怪,最难以理解的问题。当我加载页面时会发生这种情况:

>python manage.py runserver

Validating models...

0 errors found
Django version 1.3.1, using settings 'ponysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[01/Nov/2011 01:21:49] "GET / HTTP/1.0" 500 102747

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 284, in run
    self.finish_response()
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 324, in finish_response
    self.write(data)
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 420, in write
    self._write(data)
  File "C:\Python27\lib\socket.py", line 324, in write
    self.flush()
  File "C:\Python27\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10054] An existing connection was forcibly closed by the remote host
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 63095)
Traceback (most recent call last):
  File "C:\Python27\lib\SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 570, in __init__
    BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "C:\Python27\lib\SocketServer.py", line 641, in __init__
    self.finish()
  File "C:\Python27\lib\SocketServer.py", line 694, in finish
    self.wfile.flush()
  File "C:\Python27\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10054] An existing connection was forcibly closed by the remote host
----------------------------------------
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 284, in run
    self.finish_response()
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 324, in finish_response
    self.write(data)
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 420, in write
    self._write(data)
  File "C:\Python27\lib\socket.py", line 324, in write
    self.flush()
  File "C:\Python27\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10054] An existing connection was forcibly closed by the remote host
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 63099)
Traceback (most recent call last):
  File "C:\Python27\lib\SocketServer.py", line 284, in _handle_request_noblock
    self.process_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 310, in process_request
    self.finish_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 323, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 570, in __init__
    BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
  File "C:\Python27\lib\SocketServer.py", line 641, in __init__
    self.finish()
  File "C:\Python27\lib\SocketServer.py", line 694, in finish
    self.wfile.flush()
  File "C:\Python27\lib\socket.py", line 303, in flush
    self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 10054] An existing connection was forcibly closed by the remote host
----------------------------------------

[01/Nov/2011 01:21:53] "GET / HTTP/1.0" 500 102391

我尝试过擦除并重新创建数据库,将views.pymodels.py简化为最低限度,但无济于事。我也尝试在另一台计算机上运行相同的项目,结果相同。两者都运行Windows x64。实际上,我认为一台计算机正在运行Django 1.3.x和1.2.x版本,但无论如何错误看起来都是一样的。

以下是完整的追溯:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 1.3.1
Python Version: 2.7.2

Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'forum',
 'django.contrib.markup']

Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')

Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  101.                             request.path_info)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in resolve
  250.             for pattern in self.url_patterns:
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in _get_url_patterns
  279.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Python27\lib\site-packages\django\core\urlresolvers.py" in _get_urlconf_module
  274.             self._urlconf_module = import_module(self.urlconf_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py" in import_module
  35.     __import__(name)
File "C:\Users\kiwi\Dropbox\Programming Projects\Django Projects\ponysite\..\ponysite\urls.py" in 
  3. admin.autodiscover()
File "C:\Python27\lib\site-packages\django\contrib\admin\__init__.py" in autodiscover
  26.             import_module('%s.admin' % app)
File "C:\Python27\lib\site-packages\django\utils\importlib.py" in import_module
  35.     __import__(name)
File "C:\Users\kiwi\Dropbox\Programming Projects\Django Projects\ponysite\forum\admin.py" in 
  1. from forum.models  import Category, Thread, Post, Report, Subscription, Ban

Exception Type: ImportError at /
Exception Value: cannot import name Ban

Banmodels.py中导入的模型(导入views.py)我玩了一段时间,但目前在我的模型,视图和控制器中都被注释掉了。我不知道它是否与这个问题有任何关系。

先谢谢你们。

1 个答案:

答案 0 :(得分:5)

基于这一行:

File "C:\Users\kiwi\Dropbox\Programming Projects\Django Projects\ponysite\forum\admin.py" in
1. from forum.models  import Category, Thread, Post, Report, Subscription, Ban

Django在forum / admin.py

中找到
from forum.models  import Category, Thread, Post, Report, Subscription, Ban

注意最后的Ban未在模型中定义。删除它,错误应该消失。