I am following the tutorial for Django. I am stuck on the last part of the documentation page: resuable_apps.
The package/module I want to use is
/django-polls/ in /mysite/
When I am trying to make the app pluggable by removing it from the project sub-directory to a directory of the same level something goes wrong.
My file hierarchy is as follows:
django-polls mysite
./django-polls:
LICENSE docs
MANIFEST.in polls
README.rst setup.cfg
dist setup.py
django_polls.egg-info
./django-polls/dist:
django-polls-0.1.tar.gz
./django-polls/django_polls.egg-info:
PKG-INFO dependency_links.txt
SOURCES.txt top_level.txt
./django-polls/docs:
./django-polls/polls:
__init__.py migrations urls.py
__pycache__ models.py views.py
admin.py static
apps.py tests.py
./django-polls/polls/__pycache__:
__init__.cpython-38.pyc tests.cpython-38.pyc
admin.cpython-38.pyc urls.cpython-38.pyc
apps.cpython-38.pyc views.cpython-38.pyc
models.cpython-38.pyc
./django-polls/polls/migrations:
0001_initial.py __init__.py __pycache__
./django-polls/polls/migrations/__pycache__:
0001_initial.cpython-38.pyc
__init__.cpython-38.pyc
./django-polls/polls/static:
polls
./django-polls/polls/static/polls:
images style.css
./django-polls/polls/static/polls/images:
background.gif
./mysite:
db.sqlite3 mysite
manage.py templates
./mysite/mysite:
__init__.py asgi.py urls.py
__pycache__ settings.py wsgi.py
./mysite/mysite/__pycache__:
__init__.cpython-38.pyc urls.cpython-38.pyc
settings.cpython-38.pyc wsgi.cpython-38.pyc
./mysite/templates:
admin polls
./mysite/templates/admin:
base_site.html
./mysite/templates/polls:
detail.html index.html results.html
When I run ‘python manage.py runserver’ in the /mysite/ directory I get back “ModuleNotFoundError: No module named ‘polls’.”
My mysite/settings.py file is:
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 3.1.5.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '#lhl+l#0!)tl1f$a2r#_n^la4t%bic4x)=ro0$h0dbd*y@yf@s'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
# 'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'mysite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / '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 = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/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/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/Los_Angeles'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
(django-polls/polls/):
My apps.py is:
from django.apps import AppConfig
class PollsConfig(AppConfig):
name = 'polls'
If you have finished the documentation tutorial, please let me know how how get past the last part where we move the /polls/ directory into the /django-polls/ directory! Thank you very much.