Python导入错误,我无法理解导入限制?

时间:2014-08-11 10:17:38

标签: python django python-2.7 django-models python-import

这是文件夹结构。

- Project
     • App
         - __init__.py
         - admin.py
         - urls.py
         - views.py
         - models.py
         - serializers.py
     • test.py
     • Project
         - __init__.py
         - settings.py
         - urls.py
         - wsgi.py
     • manage.py
     • tmp.db

问题在于,当我尝试导入App>模型时,无论我尝试什么,我都会收到错误。

test.py文件包含以下内容[摘录]

import os
import sys
import re
from datetime import datetime, timedelta

import httplib2
from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import argparser, run_flow
from App.models import ModelName

我甚至尝试直接检查python shell。我从Project文件夹中点击以下语句。

from App.models import ModelName

以下是我得到的错误。 [使用错误文本更新,而不是图像!]

>>> from App.models import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "App/models.py", line 1, in <module>
    from django.db import models
  File "/Library/Python/2.7/site-packages/django/db/models/__init__.py", line 5, in <module>
    from django.db.models.query import Q
  File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 17, in <module>
    from django.db.models.deletion import Collector
  File "/Library/Python/2.7/site-packages/django/db/models/deletion.py", line 4, in <module>
     from django.db.models import signals, sql
  File "/Library/Python/2.7/site-packages/django/db/models/sql/__init__.py", line 4, in <module>
     from django.db.models.sql.subqueries import *
  File "/Library/Python/2.7/site-packages/django/db/models/sql/subqueries.py", line 12, in <module>
     from django.db.models.sql.query import Query
  File "/Library/Python/2.7/site-packages/django/db/models/sql/query.py", line 22, in <module>
     from django.db.models.sql import aggregates as base_aggregates_module
  File "/Library/Python/2.7/site-packages/django/db/models/sql/aggregates.py", line 9, in <module>
     ordinal_aggregate_field = IntegerField()
  File "/Library/Python/2.7/site-packages/django/db/models/fields/__init__.py", line 116, in __init__
     self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
     self._setup(name)
  File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 47, in _setup
     % (desc, ENVIRONMENT_VARIABLE))

django.core.exceptions.ImproperlyConfigured:请求设置DEFAULT_INDEX_TABLESPACE,但未配置设置。您必须先定义环境变量DJANGO_SETTINGS_MODULE或在访问设置之前调用settings.configure()。

0 个答案:

没有答案