Using Django==3.1, when I try and go to the admin pages, I'm getting the error
raise TemplateDoesNotExist(template_name, chain=chain) admin/apidocs_index.html
I never used to get this happening.
my urls:
urlpatterns = [
path('copo/', include('web.apps.web_copo.urls', namespace='copo')),
path('admin/', admin.site.urls),
path('rest/', include('web.apps.web_copo.rest_urls', namespace='rest')),
path('api/', include('api.urls', namespace='api')),
path('accounts/', include('allauth.urls')),
path('accounts/profile/', views.index),
path('', TemplateView.as_view(template_name="index.html"), name='index')
]
and template settings
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
os.path.join(BASE_DIR, 'web', 'landing'),
os.path.join(BASE_DIR, 'web', 'apps', 'web_copo', 'templates', 'copo'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.csrf',
'django.template.context_processors.request',
'django.template.context_processors.static',
# processor for base page status template tags
"web.apps.web_copo.context_processors.get_status",
"web.apps.web_copo.context_processors.add_partial_submissions_to_context",
'django.contrib.auth.context_processors.auth',
],
'debug': True,
},
},
]
I don't have any more details to add at this time
Related
I started Django few days ago and I am stuck now.
I got error like this.
django.template.exceptions.TemplateDoesNotExist: home.html
but I don't know how to fix it.
views.py
from django.shortcuts import render
from django.http import HttpResponse
from .models import ToDoList, Item
def index(response, id):
ls = ToDoList.objects.get(id=id)
return render(response, "main/base.html", {"name":ls.name})
def home(response):
return render(response, "main/home.html", {'name':'test'})
base.html
<html> <head> <title>Website</title> </head> <body> <p>{{name}}</p> </body> </html>
home.html
{% extends 'main/base.html' %}
Both html files are in file named templates
I thought template might have something to do with it and checked it.
setting.py
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',
],
},
},
]
Does someone help me out?
Just add your root template folder name to the DIRS value.
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": ["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",
],
},
},
]
You have to have both files in folder: <project_name>/<app_name>/main/, but you probably put it somewhere else.
Additionally, it's good practice to add this value to TEMPLATES["DIRS"]:
"DIRS": [os.path.join(PROJECT_DIR, "templates")],
and then create folder "templates" inside every app you have and store templates inside (move there your whole folder "main" with proper templates)
do this:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR,"templates",
os.path.join(BASE_DIR,"appname","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',
],
},
},
]
I am getting TemplateDoesNotExist at /account issues in my website, all code is working perfect on my localhost but this issue is coming on server, please let me know where is the mistake.
Here is my urls.py file...
app_name='account'
urlpatterns = [
path('account', views.accounts, name='useraccount'),
]
here is my views.py file...
def accounts(request):
return render(request, 'account/account.html')
my account.html file path is this....account(app name)/templates/account/account.html
and this is link...
<li>
Account
</li>
here is the value of TEMPLATES in setting.py file...
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',
'mainpage.context_processors.context_categories',
],
},
},
]
i want to customize django-oscar template according to my requirement , when i modified the checkout page, i had been encoutred with this error :
TemplateSyntaxError at /checkout/thank-you/
Invalid block tag on line 132: 'oscar_thumbnail', expected 'endwith'. Did you forget to register or load this tag?
this my settings.py :
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'),
OSCAR_MAIN_TEMPLATE_DIR
]
,
# 'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.i18n',
'django.contrib.messages.context_processors.messages',
'oscar.apps.search.context_processors.search_form',
'oscar.apps.promotions.context_processors.promotions',
'oscar.apps.checkout.context_processors.checkout',
'oscar.apps.customer.notifications.context_processors.notifications',
'oscar.core.context_processors.metadata',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
},
},
]
how i can register the templatetag into my custom template in django-oscar?
I Have been reading about templates in the django book, the author has suggested to add template path in the setting.py variable TEMPLATE_DIRS but my setting.py has no `TEMPLATE_DIRS'(I understand why is it so)and I could find the below
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(__file__), ’templates’).replace(’\\’,’/] #1
'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',
],
},
},
]
1)Does the above change I have madein the settings.py lead to me in the correct direction or is there any better way to do it? I wanna make myself sure before I put my self into others and end up in mess.
TEMPLATE_DIRS variable is deprecated since Django 1.8 (https://docs.djangoproject.com/en/1.9/ref/settings/#template-dirs).
Your setup is fine, but you can clean it up a bit, for example:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
os.path.join(BASE_DIR, 'templates', 'some_other_dir'),
# other paths
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.template.context_processors.media',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
We're trying to override the admin page for Django 1.6, but it continues to get it from django/contrib/templates/...:
settings.py:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
[os.path.join(BASE_DIR, 'templates')],
],
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
'loaders': [
# insert your TEMPLATE_LOADERS here
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]
},
},
]
]
and the files structure:
project
project
templates
app_name
admin
file_to_override <--it varies here from being inside the app_name or inside template itself
I'm not sure why the directories arent working
I don't know why you're using Django 1.6, but the TEMPLATES dict syntax you quote is only for Django 1.8+. In previous versions, you need to specify all the options individually.
Also note you have wrongly surrounded the DIRS value with two list brackets.
TEMPLATE_DIRS = [
os.path.join(BASE_DIR, 'templates'),
]
TEMPLATE_CONTEXT_PROCESSORS = [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
]
TEMPLATE_LOADERS = [
# insert your TEMPLATE_LOADERS here
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]