这是/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})
这是我的PyCharm CE中的追溯信息:
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
在我的/app03/models.py
:
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_bussiness
表:
为什么没有属性'Bussiness'?
答案 0 :(得分:1)
您应该直接从您的应用模型导入该类。您目前与Django的models
模块存在冲突,该模块与您的应用中具有相同名称models
:
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})