我正在关注《The Definitive Guide to Django》一书,我开始注意到的一件事是,每当我在模型文件中出现一个错误时,服务器就会挂起,并且在修复错误后不会自动重新启动。
这是一个例子:我用这样的一行保存文件
email = models.EmailField(blank=Tru)
这引发了明显的错误和堆栈跟踪
Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.core.management.commands.runserver.Command object at 0x00000000025B0400>>
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python27\lib\site-packages\django\core\management\validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 158, in get_app_errors
self._populate()
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 64, in _populate
self.load_app(app_name, True)
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\....\models.py", line 17, in <module>
class Author(models.Model):
File "C:\...\models.py", line 20, in Author
email = models.EmailField(blank=Tru)
NameError: name 'Tru' is not defined
现在,如果我更改Tru
为True
,服务器不会重新启动。这是故意的吗?还是我的申请有问题?我刚刚开始学习 Django,所以我不知道这是否是常见行为。
我在 Windows 上,运行 Python 2.7.3 和 Django 1.4.1。