Django 1.6 Admin Page Overriding Not Working - django

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

Related

Why is Django admin giving me TemplateDoesNotExist Error

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

How to customize template in django-oscar?

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?

Overriding Admin Templates in django 1.11

I don't get django 1.11 to accept a new base_site.html:
Following docs and some posts i copied the file to:
BASE_DIR/templates/base_site.html and
BASE_DIR/templates/admin/base_site.html
in settings.py:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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',
],
'loaders': (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
),
},
},
]
I tried that with the file in templates and in templates/admin:
>>> print ( os.path.isfile((os.path.join(settings.BASE_DIR, 'templates', 'admin','base_site.html'))) )
True
>>> print ( os.path.isfile((os.path.join(settings.BASE_DIR, 'templates', 'base_site.html'))) )
True
If you want to override admin files they must exist in admin folder inside templates folder like below
your_project
your_project
|-- your_project/
|-- myapp/
|-- templates/
|-- admin/
|-- base_site.html
here file name base_site.html must be same as the file name in original admin folder.
base_site.html
{% extends "admin/base.html" %}
# you can write changes here
Just had this problem and literally fixed it by installing django-apptemplates and adding it as a loader into settings.py:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [PROJECT_DIR],
'APP_DIRS': False,
'OPTIONS': {
'loaders': [
# ADD LOADER HERE
'apptemplates.Loader',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
**APP_DIRS will have to be set to False in order for this to work
To override the base_site.html of Django admin, add the custom base_site.html such that it's path is BASE_DIR/templates/admin/base_site.html. This works in Django 1.11 as well.

Adding template path Django

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

templets not found error in django

I am little bit confused about django templates, I have attached screen shot of workspace, can some one please tell how can I use addprofile.html template in my views.py in buddy app.
In my settings/base.py I have mentioned templates in following way:
# Build paths inside the project like this: join(BASE_DIR, "directory")
BASE_DIR = dirname(dirname(dirname(__file__)))
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
STATICFILES_DIRS = [join(BASE_DIR, 'static')]
MEDIA_ROOT = join(BASE_DIR, 'media')
MEDIA_URL = "/media/"
# Use Django templates using the new Django 1.8 TEMPLATES settings
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
join(BASE_DIR, 'templates'),
# insert more TEMPLATE_DIRS here
join(PROJECT_PATH, 'templates/')
],
'APP_DIRS': True,
'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',
],
},
},
]
I am new to Django and python and this is my first app in django
create following structure:
buddy (this is your existing budy app folder)/templates (this is existing folder)/buddy (this is new folder) and place all your templates: addprofile.html, edit_profile.html, show_profile.html, success.html withing this path.
edit your settings 'DIRS' so it looks as follows:
'DIRS': [
join(BASE_DIR, 'templates'),
join(PROJECT_PATH, 'templates/'),
join(BASE_DIR, 'buddy/templates')