|
from django.db import models
class Topic(models.Model):
"""A topic the user is learning about."""
text = models.CharField(max_length=200)
date_added = models.DateTimeField(auto_now_add=True)
def __str__(self):
"""Return a string representation of the model."""
return self.text
我在学Django编写上面的代码并运行它的时候,出现了
Traceback (most recent call last):
File "D:\python_Django\ll_env\Scripts\learning_logs\models.py", line 3, in <module>
class Topic(models.Model):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\base.py", line 108, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\registry.py", line 253, in get_containing_app_config
self.check_apps_ready()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\registry.py", line 135, in check_apps_ready
settings.INSTALLED_APPS
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\django\conf\__init__.py", line 82, in __getattr__
self._setup(name)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python39\lib\site-packages\django\conf\__init__.py", line 63, in _setup
raise ImproperlyConfigured(
django.core.excepti**.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
请问怎么解决
(《python从入门到实践》18.2.1) |
|