2016-07-24 6 views
0

私は最初のモデルを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の

私のウェブサイトの構造は、へ 1)first\books(models) 2)first\first 3)first\manage.py

私の変化である

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

設定は、誰もが私が立ち往生したいくつかの光を当てることができます

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' 
] 

を提出します。

My directory stucture

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 

my 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/' 
+0

あなたが 'python manage.py startapp ... 'を実行したときに、どのような名前でアプリケーションを作ったのですか? –

+0

モーゼス、私は書籍として –

+0

という名前を付けました。' first.books'ではなく、 'first' INSTALLED_APPS –

答えて

1

あなたのアプリは、あなたのINSTALLED_APPS設定でapp_nameとして含まれるべき、books名付けのでbooks(とないfirst.books)されます。

+0

モーゼス、それはキックインしない、また、私はデフォルトをコメントアウトする方法は正しい行動ではないですか? –

+0

いいえ、コメントアウトしてはいけません。 Djangoはあなたのプロジェクトが正しく動作するようにする必要があります –

+0

はい、おかげで2つの間違いfirst.appとその後のコメントが誤解されてしまった:) –

関連する問題