在《python编程呢个:从入门到实践》一书创建网页的应用程序时需要定义模型如下:
from django.db import models
class Topic(models.Model):
"""用户学习的主题"""
text = models.CharField(max_length=200)
date_added = models.DateTimeField(auto_now_add=True)
def __str__(self):
"""返回模型的字符串表示"""
return self.text
但是运行的时候出现如下错误:
Traceback (most recent call last):
File "D:/pycharm/learning_log/models.py", line 3, in <module>
class Topic(models.Model):
File "D:\pycharm\learning_log\django\db\models\base.py", line 87, in __new__
app_config = apps.get_containing_app_config(module)
File "D:\pycharm\learning_log\django\apps\registry.py", line 249, in get_containing_app_config
self.check_apps_ready()
File "D:\pycharm\learning_log\django\apps\registry.py", line 131, in check_apps_ready
settings.INSTALLED_APPS
File "D:\pycharm\learning_log\django\conf\__init__.py", line 57, in __getattr__
self._setup(name)
File "D:\pycharm\learning_log\django\conf\__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.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.
Process finished with exit code 1
求教大神赐教如何解决!!!