0
我有一個項目,有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
我有類測試的內部,即引起錯誤的一個。這是引發錯誤(specimens.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):
...
而我的測試類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
是保留字?
在此先感謝!
你是否試圖打開你的python shell並單獨導入'tests'模塊?如果你能夠做到這一點,然後尋找它的路徑:'import tests; print tests .__ file__'。也許這不是你所期望的。 – Germano
你有循環依賴。您沒有足夠的代碼來確切知道它在哪裏,但是tests.models正在導入projects.models和specimen.models,並且很可能其中一個導入了tests.models,因此是導入循環。 –
請檢查它:'python manage.py shell'。然後'從tests.models導入Test'。它會返回什麼?它是好還是不好? – Mortezaipo