0

我是 Python 和 Django 的新手。我不明白的是:

为什么如果我使用这段代码(来自 django 教程):

from django.db import models

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

    # other functions...


class Choice(models.Model):
    poll = models.ForeignKey(Poll)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

一切都manage.py shell很好。当我尝试在 SublimeText2 中构建此代码时,出现以下错误:

django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

为什么在第二种情况下 Django 不知道settings要使用哪个文件?

4

0 回答 0