我有一个包含3个应用程序的项目,称为项目,标本和测试。这个工作正常,直到我做出改变(我不记得是什么)。在那之后,Django抛出ImportError: No module named models.
我无法想象这是什么问题,因为我认为我已经很好地引用和组织了。
这是我的错误:
ImportError at /
No module named models
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.5.5
Exception Type: ImportError
Exception Value:
No module named models
Exception Location: /home/david/mysqldb/dev/mysqldb/teams_db/specimens/views.py in <module>, line 11
Python Executable: /usr/bin/python
Python Version: 2.7.5
这是我的追溯:
/home/david/mysqldb/dev/mysqldb/teams_db/teams_db/urls.py in <module>
(r'^specimens/', include('specimens.urls')),
▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py in include
urlconf_module = import_module(urlconf_module)
▶ Local vars
/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py in import_module
__import__(name)
▶ Local vars
/home/david/mysqldb/dev/mysqldb/teams_db/specimens/urls.py in <module>
from views import new_specimen, list_specimens, info_specimen
▶ Local vars
/home/david/mysqldb/dev/mysqldb/teams_db/specimens/views.py in <module>
from tests.models import Test
▶ Local vars
在应用程序tests
内部,我有类Test,导致错误的类。这是抛出错误的函数(samples.views):
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect,\
HttpResponseForbidden, HttpResponseBadRequest,\
HttpResponseServerError
from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.shortcuts import render_to_response, get_object_or_404
from forms import SearchForm, SpecimenForm
from projects.models import Project, Serie
from models import Specimen
from tests.models import Test ## Test importation!!
import simplejson
import json
from django.core import serializers
from django.forms.models import model_to_dict
import datetime
def new_specimen(request, project_id=None, serie_id=None):
...
我在test.models中的Test类:
from django.db import models
from projects.models import Project
from specimens.models import Specimen
#from operator.models import Operator
from django.core.validators import RegexValidator
class Test(models.Model):
ref = models.CharField(max_length=70, unique=True)
#name = models.CharField(max_length=70, null=True, blank=True, default='NULL')
project = models.ForeignKey(Project)
specimen = models.ForeignKey(Specimen)
#operator = models.ForeignKey(Operator)
notes = models.TextField(max_length=170, blank=True)
description = models.TextField(max_length=170, blank=True)
start_date = models.DateField(null=True, blank=True)
finish_date = models.DateField(null=True, blank=True)
status = models.CharField(max_length=70, blank=True)
您需要更多信息吗?如有必要,请告诉我。有什么想法吗?可能是名称tests
是保留字?
提前致谢!!
答案 0 :(得分:0)
它看起来像一个导入循环,但我怀疑你在其他任何地方导入Test
模型。不要在视图from models import Specimen
中使用相对导入,这可能会导致您的问题。并且不要在tests.py
中放置任何模型,它只应用于测试,并且您不需要任何测试模型进行测试。