I'm following the book The Definitive Guide to Django and one thing I've started noticing is that whenever I make a single error in my models file, the server just hangs and is not automatically restarted when the error is fixed.
Here's an example: I save the file with a line like this
email = models.EmailField(blank=Tru)
Which raises the obvious error and stack trace
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
Now, if I change Tru to True, the server does not restart. Is this intentional? Or is there something wrong with my application? I've just started learning Django so I have no idea if this is common behaviour.
I'm on Windows, running Python 2.7.3 and Django 1.4.1.
Not just you- I also experience this on occasion.
Although the development server is usually pretty good about restarting after code changes, some particularly egregious errors (especially in your models.py) can sometimes cause it to hang. Just need to terminate it (Ctrl+C), restart it, and continue along your merry way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With