检查模型时出现属性错误

拉加姆

我正在django中创建我的第一个模型,我一直在关注与我使用的django版本相比早于django的书,我创建了一个应用程序书并编写了以下模型

from django.db import models

#Create your models here.

    class Publisher(models.Model):
        name = models.CharField(max_length=30)
        address = models.CharField(max_length=50)
        city = models.CharField(max_length=60)
        state_province = models.CharField(max_length=30)
        country = models.CharField(max_length=50)
        website = models.URLField()
    class Author(models.Model):
        first_name = models.CharField(max_length=30)
        last_name = models.CharField(max_length=40)
        email = models.EmailField()
    class Book(models.Model):
        title = models.CharField(max_length=100)
        authors = models.ManyToManyField(Author)
        publisher = models.ForeignKey(Publisher)
        publication_date = models.DateField()

当我使用它检查时,py manage.py检查它给

AttributeError: module 'first' has no attribute 'books'

我的网站结构是 1)first\books(models) 2)first\first 3)first\manage.py

我对设置文件的更改

INSTALLED_APPS = [
    #'django.contrib.admin',
    #'django.contrib.auth',
    #'django.contrib.contenttypes',
    #'django.contrib.sessions',
    #'django.contrib.messages',
    #'django.contrib.staticfiles',
    'first.books' -- I commented the defaults as described in the book
]

MIDDLEWARE_CLASSES = [
    #'django.middleware.security.SecurityMiddleware',
    #'django.contrib.sessions.middleware.SessionMiddleware',
    #'django.middleware.csrf.CsrfViewMiddleware',
    #'django.contrib.auth.middleware.AuthenticationMiddleware',
    #'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    #'django.contrib.messages.middleware.MessageMiddleware',
    #'django.middleware.clickjacking.XFrameOptionsMiddleware'
]

谁能给我一些启示?

我的目录结构

C:\Program Files\Python35\mywebapp\first>tree /f
Folder PATH listing
Volume serial number is CE58-0759
C:.
│   db.sqlite3
│   manage.py
│
├───books
│   │   admin.py
│   │   apps.py
│   │   models.py
│   │   tests.py
│   │   views.py
│   │   __init__.py
│   │
│   └───migrations
│           __init__.py
│
└───first
    │   settings.py
    │   urls.py
    │   views.py
    │   wsgi.py
    │   __init__.py
    │
    ├───template
    │       basic.html
    │
    └───__pycache__
            settings.cpython-35.pyc
            urls.cpython-35.pyc
            views.cpython-35.pyc
            wsgi.cpython-35.pyc
            __init__.cpython-35.pyc

我的settings.py

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '*********'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    ''''django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles','''
    'first.books',
]

MIDDLEWARE_CLASSES = [
   ''' 'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware','''
]

ROOT_URLCONF = 'first.urls'
import os.path
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(os.path.dirname(__file__) ,'template').replace('\\','/')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'first.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
摩西·科莱多耶(Moses Koledoye)

您的应用程序被命名books,所以books(不first.books)应该包括为app_name你的INSTALLED_APPS设置。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Mac:检查扩展属性文件时出现I / O错误

来自分类Dev

在 try 循环中检查属性时出现硒错误

来自分类Dev

将新模型添加到模型属性中时出现NullReference错误

来自分类Dev

Django,在manage.py检查或sync.db时出现“错误:模块:无法导入模型”

来自分类Dev

使用Spring MVC验证模型属性时出现400错误的请求

来自分类Dev

在 Keras 的序列模型中添加 Conv2D 时出现属性错误

来自分类Dev

为 TensorFlow Serving 导出 textsum 模型时出现错误“str”对象没有属性“dtype”

来自分类Dev

从加载的 Keras 模型调用“predict_generator”时出现属性错误

来自分类Dev

尝试导航时出现模型方法错误

来自分类Dev

检查子类时出现“ instanceOf”错误

来自分类Dev

检查指针时出现分段错误

来自分类Dev

检查更新时出现404错误

来自分类Dev

检查参数时出现陷阱错误

来自分类Dev

新模型在保存时给出属性错误

来自分类Dev

新模型在保存时给出属性错误

来自分类Dev

使用icontains时出现属性错误

来自分类Dev

定义顶点属性时可能出现的错误

来自分类Dev

尝试访问其他模型的属性时出现NoMethodError

来自分类Dev

从_layout.cshtml访问模型属性时出现问题

来自分类Dev

调用函数模型时出现CodeIgniter Undefined属性

来自分类常见问题

调用LSTM模型的预测函数时出现输入形状错误

来自分类Dev

尝试在视图中使用模型时出现MVC错误

来自分类Dev

修改SqlAlchemy模型时出现Unhashable Type错误

来自分类Dev

创建模型时出现错误的复数形式

来自分类Dev

在tensorflow 2.0中运行RNN LSTM模型时出现错误

来自分类Dev

使用theano后端加载keras模型时出现断言错误

来自分类Dev

Django:导入模型时出现模块未找到错误

来自分类Dev

导出到ONP量化的Pytorch模型时出现分段错误

来自分类Dev

运行sklearn分类器模型时出现值错误

Related 相关文章

  1. 1

    Mac:检查扩展属性文件时出现I / O错误

  2. 2

    在 try 循环中检查属性时出现硒错误

  3. 3

    将新模型添加到模型属性中时出现NullReference错误

  4. 4

    Django,在manage.py检查或sync.db时出现“错误:模块:无法导入模型”

  5. 5

    使用Spring MVC验证模型属性时出现400错误的请求

  6. 6

    在 Keras 的序列模型中添加 Conv2D 时出现属性错误

  7. 7

    为 TensorFlow Serving 导出 textsum 模型时出现错误“str”对象没有属性“dtype”

  8. 8

    从加载的 Keras 模型调用“predict_generator”时出现属性错误

  9. 9

    尝试导航时出现模型方法错误

  10. 10

    检查子类时出现“ instanceOf”错误

  11. 11

    检查指针时出现分段错误

  12. 12

    检查更新时出现404错误

  13. 13

    检查参数时出现陷阱错误

  14. 14

    新模型在保存时给出属性错误

  15. 15

    新模型在保存时给出属性错误

  16. 16

    使用icontains时出现属性错误

  17. 17

    定义顶点属性时可能出现的错误

  18. 18

    尝试访问其他模型的属性时出现NoMethodError

  19. 19

    从_layout.cshtml访问模型属性时出现问题

  20. 20

    调用函数模型时出现CodeIgniter Undefined属性

  21. 21

    调用LSTM模型的预测函数时出现输入形状错误

  22. 22

    尝试在视图中使用模型时出现MVC错误

  23. 23

    修改SqlAlchemy模型时出现Unhashable Type错误

  24. 24

    创建模型时出现错误的复数形式

  25. 25

    在tensorflow 2.0中运行RNN LSTM模型时出现错误

  26. 26

    使用theano后端加载keras模型时出现断言错误

  27. 27

    Django:导入模型时出现模块未找到错误

  28. 28

    导出到ONP量化的Pytorch模型时出现分段错误

  29. 29

    运行sklearn分类器模型时出现值错误

热门标签

归档