Python 属性错误:';模块';对象没有属性';业务';

Python 属性错误:';模块';对象没有属性';业务';,python,django,Python,Django,这是/app03/views.py: from django.db import models def business(request): v = models.Bussiness.objects.all() # this is the line10 # QuerySet # [obj(id, caption, code), obj,obj...] return render(request, '/app03/business.html', {'v':v}

这是
/app03/views.py

from django.db import models

def business(request):
    v = models.Bussiness.objects.all()   # this is the line10
    # QuerySet
    # [obj(id, caption, code), obj,obj...]
    return render(request, '/app03/business.html', {'v':v})
class Bussiness(models.Model):
    caption = models.CharField(max_length=32)
    code = models.CharField(max_length=32, default='SA')
这是my Pyce中的回溯信息:

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Library/Python/2.7/site-packages/Django-1.11.2-py2.7.egg/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/luowensheng/Desktop/TestIOS/TestPython/pyProject/app03/views.py", line 10, in business
    v = models.Bussiness.objects.all()
AttributeError: 'module' object has no attribute 'Bussiness'
[14/Aug/2017 09:27:27] "GET /app03/business/ HTTP/1.1" 500 64817
在my
/app03/models.py
中:

from django.db import models

def business(request):
    v = models.Bussiness.objects.all()   # this is the line10
    # QuerySet
    # [obj(id, caption, code), obj,obj...]
    return render(request, '/app03/business.html', {'v':v})
class Bussiness(models.Model):
    caption = models.CharField(max_length=32)
    code = models.CharField(max_length=32, default='SA')
我做了这个手术:

python manage.py makemigrations
python manage.py migrate 
在db.sqlite3中,生成了
app03\u business
表:


为什么没有“业务”属性

您应该直接从应用程序模型导入类。您当前与Django的
模型
模块存在冲突,该模块与您应用程序中的同名
模型

from django.db import models
from app03.models import Bussiness

def business(request):
    v = Bussiness.objects.all()   # this is the line10
    # QuerySet
    # [obj(id, caption, code), obj,obj...]
    return render(request, '/app03/business.html', {'v':v})

如何导入
models
模块?@Kendas in views.py我导入了。您导入的是
django.db.models
模块,而不是
app03.models
模块。第一个不包含您的
业务
模型。下面的答案应该是正确的。但是,我有一个名为app02的类似目录,它使用像app03这样的模型,没有这个错误,我不知道从哪里得到这个冲突。您可能不需要将
django.db.models
导入到您的视图中,其中包含自定义模型继承的类。您应该从每个应用程序导入每个模型类。