在另一个文件中导入模型时出错。基本上我想用
>>> from mysite.blog.models import Blog
>>> b = Blog(name='Beatles Blog', tagline='All the latest Beatles news.')
>>> b.save()
但在 python 文件 [scrap.py] 中向模型添加值,但在此文件中导入模型时出错。有什么帮助吗??
from models import QuestionBox // Error in this line
错误回溯:
Traceback (most recent call last):
File "scrap.py", line 1, in <module>
from models import QuestionBox
File "/home/sourabh/Django/QASite/QAsite/QAapp/models.py", line 1, in <module>
from django.db import models
File "/home/sourabh/Django/QASite/local/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/home/sourabh/Django/QASite/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/home/sourabh/Django/QASite/local/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in _setup
% (desc, ENVIRONMENT_VARIABLE))
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.
目录树
.
|-- manage.py
|-- QAapp
| |-- __init__.py
| |-- __init__.pyc
| |-- migrations
| | |-- 0001_initial.py
| | |-- 0001_initial.pyc
| | |-- 0002_initial.py
| | |-- 0002_initial.pyc
| | |-- 0003_initial.py
| | |-- 0003_initial.pyc
| | |-- __init__.py
| | `-- __init__.pyc
| |-- models.py
| |-- models.pyc
| |-- scrap.py
| |-- tests.py
| `-- views.py
|-- QAappdb
`-- QAsite
|-- __init__.py
|-- __init__.pyc
|-- settings.py
|-- settings.pyc
|-- urls.py
`-- wsgi.py
模型文件:
class QuestionBox :
topic = models.CharField(max_length=50)
sub_topic = models.CharField(max_length=50)
question = models.TextField()
options = models.TextField()
correct_option = models.TextField()
total_attempt = models.IntegerField()
correct_attempt = models.IntegerField()