Python 突然,没有名为models的模块
我有一个包含3个应用程序的项目,叫做项目、样本和测试。在我做出改变(我不记得是什么)之前,这一切都很顺利。在那之后,Django抛出了Python 突然,没有名为models的模块,python,django,Python,Django,我有一个包含3个应用程序的项目,叫做项目、样本和测试。在我做出改变(我不记得是什么)之前,这一切都很顺利。在那之后,Django抛出了importorror:没有名为models的模块。我无法想象问题出在哪里,因为我认为我已经很好地引用和组织了所有模块 这是我的错误: ImportError at / No module named models Request Method: GET Request URL: http://127.0.0.1:8000/ Django Ver
importorror:没有名为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
以及我在tests.models中的测试类:
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
是保留字
提前谢谢 它看起来确实像一个导入循环,但我怀疑您是否可以在其他地方导入
Test
模型。不要在视图中使用“模型导入样本”中的“相对导入”,这可能会导致您的问题。不要在测试中放置任何模型。py
它应该只用于测试,测试不需要任何测试模型。您是否尝试打开python shell并单独导入测试模块?如果您能够做到这一点,那么查找它的路径:importtests;打印测试。\uuuu文件\uuuu
。也许这不是你所期望的。你有循环依赖。您没有显示足够的代码,无法准确地知道它在哪里,但是tests.models正在导入projects.models和examples.models,很可能其中一个正在导入tests.models,因此导入循环。请检查它:python manage.py shell
。然后从tests.models导入Test。它将返回什么?还好还是失败了?
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):
...
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)