I have an app where depending on its category, a tenant is either directed to the app (and templates) at /dashboard/templates/dashboard
or /dashboard2/templates/dashboard2
.
somehow, for dashboard2, the app is not found by Django and it tries to find those templates under dashboard
.
here is a dashboard2/views.py
JavaScript
x
25
25
1
@method_decorator(login_required, name='dispatch')
2
class SupplierPage2(LoginRequiredMixin,APIView):
3
def get(self, request, *args, **kwargs):
4
query = request.GET.get('search_ress', None)
5
print(query)
6
context = {}
7
8
#if query and request.method == 'GET':
9
Supplier = supplier2.objects.filter(supplier = query)
10
print(Supplier)
11
12
labels = Item2.objects.filter(fournisseur = query).values_list('reference', flat=True)[:10]
13
print(labels)
14
default_items = Item2.objects.filter(fournisseur = query).values_list('number_of_sales', flat=True)[:10]
15
print(default_items)
16
label1s = Item2.objects.filter(fournisseur = query).values_list('reference', flat=True)[:10]
17
print(label1s)
18
default_item1s = Item2.objects.filter(fournisseur = query).values_list('number_of_orders_placed', flat=True)[:10]
19
print(default_item1s)
20
21
context.update({'Supplier' : Supplier, 'labels':labels, 'default_items':default_items,'label1s':label1s, 'default_item1s':default_item1s})
22
23
24
return render(request, 'Supplier2.html',context)
25
and the error:
JavaScript
1
9
1
TemplateDoesNotExist at /Supplier2.html
2
Supplier2.html
3
Request Method: GET
4
Request URL: https://uname.website.net/Supplier2.html
5
Django Version: 3.0.5
6
Exception Type: TemplateDoesNotExist
7
Exception Value:
8
Supplier2.html
9
and the traceback:
JavaScript
1
19
19
1
Template-loader postmortem
2
Django tried loading these templates, in this order:
3
4
Using engine django:
5
6
django.template.loaders.filesystem.Loader: /home/ubuntu/website/dashboard/templates/dashboard/dashboard2/templates/dashboard2/Supplier2.html (Source does not exist)
7
django.template.loaders.app_directories.Loader: /home/ubuntu/website/customers/templates/Supplier2.html (Source does not exist)
8
django.template.loaders.app_directories.Loader: /home/ubuntu/exo/lib/python3.6/site-packages/django/contrib/auth/templates/Supplier2.html (Source does not exist)
9
django.template.loaders.app_directories.Loader: /home/ubuntu/website/dashboard/templates/Supplier2.html (Source does not exist)
10
django.template.loaders.app_directories.Loader: /home/ubuntu/website/tenantlogin/templates/Supplier2.html (Source does not exist)
11
django.template.loaders.app_directories.Loader: /home/ubuntu/website/uploadfiles/templates/Supplier2.html (Source does not exist)
12
django.template.loaders.app_directories.Loader: /home/ubuntu/exo/lib/python3.6/site-packages/django_tenants/templates/Supplier2.html (Source does not exist)
13
django.template.loaders.app_directories.Loader: /home/ubuntu/exo/lib/python3.6/site-packages/rest_framework/templates/Supplier2.html (Source does not exist)
14
django.template.loaders.app_directories.Loader: /home/ubuntu/exo/lib/python3.6/site-packages/django_tables2/templates/Supplier2.html (Source does not exist)
15
django.template.loaders.app_directories.Loader: /home/ubuntu/website/dashboard2/templates/Supplier2.html (Source does not exist)
16
django.template.loaders.app_directories.Loader: /home/ubuntu/exo/lib/python3.6/site-packages/django/contrib/admin/templates/Supplier2.html (Source does not exist)
17
django.template.loaders.app_directories.Loader: /home/ubuntu/exo/lib/python3.6/site-packages/crispy_forms/templates/Supplier2.html (Source does not exist)
18
19
when try specifying /dashboard2/Supplier2.html
I still get the same error in Django:
JavaScript
1
3
1
TemplateDoesNotExist at /Supplier2.html
2
/dashboard2/Supplier2.html
3
here is what I have in settings.py for templates:
JavaScript
1
17
17
1
TEMPLATES = [
2
{
3
'BACKEND': 'django.template.backends.django.DjangoTemplates',
4
'DIRS': [os.path.join(BASE_DIR, "dashboard/templates/dashboard", "dashboard2/templates/dashboard2")],
5
'APP_DIRS': True,
6
'OPTIONS': {
7
'context_processors': [
8
'django.template.context_processors.debug',
9
'django.template.context_processors.request',
10
'django.contrib.auth.context_processors.auth',
11
'django.contrib.messages.context_processors.messages',
12
'django.template.context_processors.i18n'
13
],
14
},
15
},
16
]
17
at this point, I don’t know what else to try
Advertisement
Answer
Fix the settings as below:
JavaScript
1
17
17
1
TEMPLATES = [
2
{
3
'BACKEND': 'django.template.backends.django.DjangoTemplates',
4
'DIRS': [os.path.join(BASE_DIR, "dashboard/templates/dashboard"), os.path.join(BASE_DIR,"dashboard2/templates/dashboard2")],
5
'APP_DIRS': True,
6
'OPTIONS': {
7
'context_processors': [
8
'django.template.context_processors.debug',
9
'django.template.context_processors.request',
10
'django.contrib.auth.context_processors.auth',
11
'django.contrib.messages.context_processors.messages',
12
'django.template.context_processors.i18n'
13
],
14
},
15
},
16
]
17