I started building my first Django app and created different models, but when I run
python manage.py validate or python manage.py sqlall books
it shows error as: import error : no module named books
Mostly, I have included the books app correctly in installed apps in settings.py, but still it is not working.
Here are my files-
-----------models.py---------
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=50)
state=models.CharField(max_length=50)
country=models.CharField(max_length=50)
website=models.CharField(max_length=50)
def __str__(self):
return self.name
class authors(models.Model):
salutation= models.CharField(max_length=30)
name=models.CharField(max_length=50)
email=models.EmailField()
headshot=models.ImageField(upload_to='/tmp')
def __str__(self):
return self.name
class book(models.Model):
title=models.CharField(max_length=50)
author=models.ForeignKey(authors)
publisher=models.ManyToManyField(publisher)
publisher_date=models.DateField()
def __str__(self):
return self.title
#code
----------------------------settings.py-------------
"""
Django settings for mytimesite project.
Generated by 'django-admin startproject' using Django 1.8.5.
For more information on this file, see
http://ift.tt/1CMZftV
For the full list of settings and their values, see
http://ift.tt/1EF8H8q
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See http://ift.tt/1CMZfK9
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '9@dol-1eeeo8j=lcot#=ab7vg=+&(fg8b(+4=o$d1lofrm1j0&'
# 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',
'mytimesite.books',
)
MIDDLEWARE_CLASSES = (
#'django.contrib.sessions.middleware.SessionMiddleware',
#'django.middleware.common.CommonMiddleware',
#'django.middleware.csrf.CsrfViewMiddleware',
#'django.contrib.auth.middleware.AuthenticationMiddleware',
#'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
#'django.contrib.messages.middleware.MessageMiddleware',
#'django.middleware.clickjacking.XFrameOptionsMiddleware',
#'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'mytimesite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['/home/sidharth/Desktop/newproject/mytimesite/templates'],
'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 = 'mytimesite.wsgi.application'
# Database
# http://ift.tt/1EF8GkO
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# http://ift.tt/1LbgPfE
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# http://ift.tt/1EF8GkR
STATIC_URL = '/static/'
Here's where models.py is located:
newproject>mytimesite>books>modules.py
where newproject contains bin and stuff. mytimesite contains manage.py and books is the app.
Aucun commentaire:
Enregistrer un commentaire