美文网首页
ImproperlyConfigured: Requested

ImproperlyConfigured: Requested

作者: NorthCity | 来源:发表于2017-02-20 14:27 被阅读0次

    在使用ipython测试django项目时,出现了下面的错误:

    In [5]: from polls.models import Polls,Choice
    ---------------------------------------------------------------------------
    ImproperlyConfigured                      Traceback (most recent call last)
    <ipython-input-5-b855efac1c5f> in <module>()
    ----> 1 from polls.models import Polls,Choice
    
    /home/mark/Workspace/Python/PythonWeb/news/polls/models.py in <module>()
          1 from django.db import models
    ----> 2 class Polls(models.Model):
          3     question = models.CharField(max_length = 200)
          4     publish_date = models.DateTimeField('pulish_datetime')
          5 
    
    /home/mark/Workspace/Python/PythonWeb/news/polls/models.py in Polls()
          1 from django.db import models
          2 class Polls(models.Model):
    ----> 3     question = models.CharField(max_length = 200)
          4     publish_date = models.DateTimeField('pulish_datetime')
          5 
    
    /usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.pyc in __init__(self, *args, **kwargs)
       1079 
       1080     def __init__(self, *args, **kwargs):
    -> 1081         super(CharField, self).__init__(*args, **kwargs)
       1082         self.validators.append(validators.MaxLengthValidator(self.max_length))
       1083 
    
    /usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.pyc in __init__(self, verbose_name, name, primary_key, max_length, unique, blank, null, db_index, rel, default, editable, serialize, unique_for_date, unique_for_month, unique_for_year, choices, help_text, db_column, db_tablespace, auto_created, validators, error_messages)
        159         self.help_text = help_text
        160         self.db_column = db_column
    --> 161         self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
        162         self.auto_created = auto_created
        163 
    
    /usr/local/lib/python2.7/dist-packages/django/conf/__init__.pyc in __getattr__(self, name)
         46     def __getattr__(self, name):
         47         if self._wrapped is empty:
    ---> 48             self._setup(name)
         49         return getattr(self._wrapped, name)
         50 
    
    /usr/local/lib/python2.7/dist-packages/django/conf/__init__.pyc in _setup(self, name)
         40                 "You must either define the environment variable %s "
         41                 "or call settings.configure() before accessing settings."
    ---> 42                 % (desc, ENVIRONMENT_VARIABLE))
         43 
         44         self._wrapped = Settings(settings_module)
    
    ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
    

    解决办法:

    在import之前加入一下代码导入settings:
     from django.conf import settings  
     settings.configure()
    

    相关文章

      网友评论

          本文标题:ImproperlyConfigured: Requested

          本文链接:https://www.haomeiwen.com/subject/blcewttx.html