Django 2.0 reusable apps - TemplateDoesNotExist at /polls/ - django

Python 3, Django 2.0
I just got to the end of the official Django tutorial, and I'm working on the advanced portion - "How to write reusable apps"
It seems like I was at least partially successful, I can access the Questions and Choices through the admin interface, but when I try to display the http://127.0.0.1:8000/polls/ I get this error: TemplateDoesNotExist at /polls/1/
I get a similar error for trying to access a detail page, at http://127.0.0.1:8000/polls/1/
I looked through all the troubleshooting questions I could, and my main question is - how can you access templates that are packaged into an app? The thing I see going wrong is that Django is trying to find the app templates inside the main project directories(ie: /tutorial/templates/polls/detail.html), but they should be "inside" the module I imported from pip.
Are you actually supposed to package the templates into apps this way? I tried throwing the template files back into tutorial/templates/polls/ and it works just fine, but this goes against what I think should be "reuseability" because then the packaged app won't have it's own templates.
The answers I was able to find seem to be more for older versions of Django, and used a TEMPLATE_LOADERS setting... Anyone know if there is a way to set that in Django 2?
Directory structure:
django-polls/
LICENSE
manifest.in
README.rst
setup.py
/dist
/docs
/polls
admin.py
apps.pyo
__init__.py
models.py
tests.py
urls.py
views.py
/build
/migrations
/static
/polls
/images
style.css
/templates
/polls
detail.html
index.html
results.html
The project structure is like this:
tutorial/
/mysite (settings.py, etc)
/templates
/admin
base_site.html
index.html
/venv (my virtualenv directory)
db.sqlite3
manage.py
settings.py
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 2.0.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
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/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '*e7#6=f$r(cu_p#7#*s+6t9r^ouio$x&06s61-0u(n1mo370c6'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
# 'polls.apps.PollsConfig',
'polls',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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': [os.path.join(BASE_DIR, 'templates', 'polls')],
'DIRS': [os.path.join(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/2.0/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/2.0/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/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/Chicago'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/'

The issue here was case: the file had been named manifest.in, when it needed to be capitalized as MANIFEST.in. Happy holidays!

Remember to include your templates directory in your MANIFEST.in file. See step 6 of packaging your app for more info.

Related

I can't seem to find a way to write into heroku's postgres from my django app

I wrote an app with Django and it has been working fine when running locally. I know deployed it with Heroku and the app run as well.
However, I when I python manage.py createsuperuser it says that I successfully created the superuser but nothing is written into Heroku Postgress DB...so I can login into neither /admin nor my app.
I have been trying debugging like crazy but I can't find the issue. Especially because if I query the DB from django Shell I do see my account, but if I check the Postgress DB of Heroku I don't.
I also checked what DB my python shell is connected to and it seems that it's sqlite, not postgres.
How do I change it so that it connects to postgres?
Also, why is it connected to Sqlite on my shell but if I try to loging on adming it checks if my user extist on postgres?
This is my settings.py
from pathlib import Path
import os
# 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.2/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
#DEBUG_PROPAGATE_EXCEPTIONS = True
ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'produceit.herokuapp.com']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'action.apps.ActionConfig',
'django_extensions',
'bootstrap_modal_forms',
'widget_tweaks',
]
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 = 'mywebsite.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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 = 'mywebsite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Parse database configuration from $DATABASE_URL
import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)
# Password validation
# https://docs.djangoproject.com/en/3.2/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.2/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/3.2/howto/static-files/
# Static files (CSS, JavaScript, Images)
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
#DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
#import django_on_heroku
#django_on_heroku.settings(locals())
import django_heroku
django_heroku.settings(locals())
Okay, so I've had this very issue so many times when I was trying to upload my website to Heroku. It worked for me the last time when I did something like this:
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '...',
'HOST': '...',
'PORT': 5432,
'USER': '...',
'PASSWORD': '...',
The name, host, user and password can all be found when you create a postresql add on in Heroku itself. You will probably already have a postres add on as default. If not you can add it yourself. You may want to search for YouTube videos, as I found this all from there. I'm not able to remember which one, but if I do, I will link it here.
When you go to your app in Heroku, go to settings and click reveal config vars. Copy the link of the db and paste it somewhere so you can use it as reference. It will be something like this.
postgres://USER:PASSWORD#HOST:PORT/NAME
It sounds like you may be creating a superuser on your local instance rather than on the version on Heroku. Give this a try to create a Django superuser on your Heroku hosted site.
heroku run python manage.py createsuperuser

TemplateDoesNotExist at / index.html error when django+react app deployed to Heroku

I created a simple django & react app (which just loads react default page for now) and I am trying to deploy to Heroku. When I run python manage.py runserver on localhost it runs fine (with default react page showing), but when I deploy it to Heroku, I get the following error:
TemplateDoesNotExist at /
index.html
This is the site : https://temp-app-test.herokuapp.com/
I'm pretty sure I included index.html in templates using os.path.join(BASE_DIR, 'build') in settings.py, but it doesn't work. I also included "postinstall": "npm run build" in scripts in package.json file.
requirements.txt
asgiref==3.2.7
Django==3.0.6
pytz==2020.1
sqlparse==0.3.1
whitenoise==5.0.1
gunicorn==20.0.4
runtime.txt
python-3.7.4
Procfile
release: python manage.py migrate
web: gunicorn test_test_test.wsgi --log-file -
settings.py
"""
Django settings for test_test_test project.
Generated by 'django-admin startproject' using Django 2.2.10.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
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/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'secret'
# 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',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'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 = 'test_test_test.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'build')],
'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 = 'test_test_test.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/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/2.2/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/2.2/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/2.2/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'build/static'),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
urls.py
from django.contrib import admin
from django.urls import path, re_path
from django.views.generic import TemplateView
urlpatterns = [
path('admin/', admin.site.urls),
re_path(r'^.*', TemplateView.as_view(template_name='index.html'),
]
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_test_test.settings')
application = get_wsgi_application()
I've been stuck here for hours, and I would like some help on this! Thanks in advance.

Cannot locate base.html in root directory. Suspect template loader as problem

I am new to python and Django. I have a base.html file in my root directory. I have a hello_world.html file in my personal_portfolio app's template file that contains {% extends "base.html" %} in hello_world.html. I have the appropriate entry in the 'DIRS': settings of my personal_portfolio project. I get a template not found error for base.html.
In the debug info I see reference to 'django.template.loaders.app_directories.load_template_source'. My impression is that when 'APP_DIRS': is True, this loader is responsible for automatically loading each apps template file in a list of directories to search for templates. I see no reference to ' 'django.template.loaders.filesystem.load_template_source' which I understand is responsible for adding directories in the 'DIRS': setting to the search list. This is how base.html should be located. However, it seems that no matter what I do only the 'django.template.loaders.app_directories.load_template_source' loader is used.
I even tried including a setting for TEMPLATE_LOADERS in settings.py.
What I did as a workaround is modify the the app_directories.py module to add the directory I am pointing to in the 'DIRS': setting. Here is the app_directories modification in E:\Python Programs\Web Projects II\rp_portfolio\venv\Lib\site-packages\django\template\loaders\app_directories.py.
#************** Revised app_directories.py
"""
Wrapper for loading templates from "templates" directories in INSTALLED_APPS
packages.
'''
from django.template.utils import get_app_template_dirs
from .filesystem import Loader as FilesystemLoader
class Loader(FilesystemLoader):
def get_dirs(self):
# ## return get_app_template_dirs('templates')
#esr revised 8/22/19
dirtup = get_app_template_dirs('templates')
dirlst = list(dirtup)
dirlst.append('E:\\Python Programs\\Web Projects II\\rp_portfolio\\templates')
dirtup2 = tuple(dirlst)
print('\n****************** app_directories.py: dirtup2:', dirtup2,'\n')
print('\n****************** app_directories.py: __file__ value:',__file__,'\n') !
return dirtup2
Above code worked and enabled locating "base.html" worked.
Why doesn't base.html load the normal way?
settings.py in personal_portfolio
"""
Django settings for personal_portfolio project.
Generated by 'django-admin startproject' using Django 2.2.4.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
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__)))
print('\n***********BASE_DIR:', BASE_DIR,'\n')
projecttemplates = (os.path.join(BASE_DIR,'templates\\'))
print('\n*******projecttemplates:', projecttemplates,'\n')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '-lql%2p2#5xy^s)fw#poz7qiw#r3rj%#_)$aufs)dpe*xs#xgr'
# 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',
'hello_world',
]
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 = 'personal_portfolio.urls'
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
)
# 'django.template.loaders.app_directories.load_template_source',
MASTER_BASE_DIR = BASE_DIR
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(MASTER_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',
],
},
},
]
print('\n************ TEMPLATES:',TEMPLATES,'\n')
WSGI_APPLICATION = 'personal_portfolio.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.2/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/2.2/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/2.2/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/2.2/howto/static-files/
STATIC_URL = '/static/'
Directory Structure

How can I set Django password emails connect to my db

I am new to django, but have set up a db and user authentication. I now have set up the password options through django auth and am using the built in templates. The problem is, I cannot receive the password reset emails from any users from my db, only the super user email. Is there a way i can redirect it to my database?
"""
Django settings for TalkingDead project.
Generated by 'django-admin startproject' using Django 1.9.1.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
import os
import posixpath
# 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: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'app',
# Add your apps here to enable them
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'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',
]
ROOT_URLCONF = 'TalkingDead.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(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 = 'TalkingDead.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/'
STATIC_ROOT = posixpath.join(*(BASE_DIR.split(os.path.sep) + ['static']))
PASSWORD_RESET_TIMEOUT_DAYS=1
# Email
EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend"
EMAIL_FILE_PATH = os.path.join(BASE_DIR, "sent_emails")
For people to receive any of Django's default User registration emails for resetting passwords, etc, you need something like the following in your urls.py of your root project folder. Although I am showing it for django 2.x, the principle is the same, so just use url() properly instead.
path('accounts/', include('accounts_app.urls')),
path('accounts/', include('django.contrib.auth.urls')), #allows change password and reset at /accounts/password_change/ and /accounts/password_reset/, and so on
You also need 'django.contrib.auth', inside the installed apps in settings.py.
And then you need a registration/ folding inside of the location of your root projects templates folder. And inside that folder, you need password_change_done.html, password_reset_email.html, and a whole buch of other templates to let them reset their password. You can find them all here.

No module named 'django.templates'

I am using python 3.4, django 1.8. I am using pycharm for developing. While running the program ,I am getting 'No module named 'django.templates'' error.
settings.py
"""
Django settings for dj project.
Generated by 'django-admin startproject' using Django 1.8.1.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# 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 https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'uhqkhi7h_w48bz*gnr+_!roaa8#c_)087a(!ees)mn2=n=lv-r'
# 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',
'blog',
)
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 = 'dj.urls'
TEMPLATES = [
{
'BACKEND': 'django.templates.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.templates.context_processors.debug',
'django.templates.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
TEMPLATE_LOADERS = (
'django.template.loaders.app_directories.load_template_source',
)
WSGI_APPLICATION = 'dj.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/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.8/howto/static-files/
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
blog/urls.py
from django.conf.urls import include, url
from . import views
urlpatterns = [
url(r'^$', views.post_list),
]
manage.py
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dj.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
post_list.html
<html>
<body>
<p>
hihiiii
</p>
</body>
</html>
dj/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'', include('blog.urls')),
]
Error
ImportError at /
No module named 'django.templates'
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.8.1
Exception Type: ImportError
Exception Value:
No module named 'django.templates'
Exception Location: C:\Python34\lib\importlib\__init__.py in import_module, line 109
Python Executable: C:\Python34\python.exe
Python Version: 3.4.1
Python Path:
['C:\\Users\\ankur anand\\PycharmProjects\\dj',
'C:\\Users\\ankur anand\\PycharmProjects\\dj',
'C:\\Windows\\SYSTEM32\\python34.zip',
'C:\\Python34\\DLLs',
'C:\\Python34\\lib',
'C:\\Python34',
'C:\\Python34\\lib\\site-packages']
Server time: Fri, 15 May 2015 18:08:59 +0530
This can happen if you are not familiar with Pycharm IDE refactoring.
You renamed the "templates" directory to another name by refactoring.
When you do this, Pycharm also renames some strings in "settings.py".
Solution: Right click your "setting.py":
LocalHistory -> ShowHistory then restore you "setting.py".
Use this and replace it existing values. As in last post he told you that you just needed to remove "s" from relevant fields. But if you couldn't understand it then just copy paste.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(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',
],
},
},
]
As the error mentions, there's no such thing as django.templates.
However, there is a django.template. You'll want to remove the s from all of the relevant lines that refer to templates.
While you're at it, you should also move your TEMPLATE_LOADERS to their proper location (within the TEMPLATES setting).
Read more in the docs.
I got the same exception with you when start my first django project...
i think maybe you changed the template dir name from 'template' to 'templates' in pycharm ,but didn't aware that pycharm changed the TEMPLATES.context_processors configs in setting.py at the sametime. it changed
django.template.context_processors.debug
django.template.context_processors.request
to
django.templates.context_processors.debug
django.templates.context_processors.request
.it's the cause of the problem.
This did happened due to Refactoring in Pycharm. I faced the same issue initially, when changed the directory name "template" to "templates".
To resolve this: Right click settings.py > local history > show history > revert.
It reverted the changes made in the settings file due to refactoring but kept the directory name to "Templates". Hence, resolving the issue.
in settings.py templates list is having key name DIRS that is empty, it should not be 'DIRS':[], RIGHT WAY -> add that value 'DIRS':[BASE_DIR / 'templates'] in settings.py
True, it is related to refactoring directory name from template to templates in my case.Need to correct change settings.py file under TEMPLATES(for me error was no module found "django.template" )
changes to be made under TEMPLATES is remove "s" from
django.templates.context_processors.debug
django.templates.context_processors.request
to:
django.template.context_processors.debug
django.template.context_processors.request