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
@method_decorator(login_required, name='dispatch') class SupplierPage2(LoginRequiredMixin,APIView): def get(self, request, *args, **kwargs): query = request.GET.get('search_ress', None) print(query) context = {} #if query and request.method == 'GET': Supplier = supplier2.objects.filter(supplier = query) print(Supplier) labels = Item2.objects.filter(fournisseur = query).values_list('reference', flat=True)[:10] print(labels) default_items = Item2.objects.filter(fournisseur = query).values_list('number_of_sales', flat=True)[:10] print(default_items) label1s = Item2.objects.filter(fournisseur = query).values_list('reference', flat=True)[:10] print(label1s) default_item1s = Item2.objects.filter(fournisseur = query).values_list('number_of_orders_placed', flat=True)[:10] print(default_item1s) context.update({'Supplier' : Supplier, 'labels':labels, 'default_items':default_items,'label1s':label1s, 'default_item1s':default_item1s}) return render(request, 'Supplier2.html',context)
and the error:
TemplateDoesNotExist at /Supplier2.html Supplier2.html Request Method: GET Request URL: https://uname.website.net/Supplier2.html Django Version: 3.0.5 Exception Type: TemplateDoesNotExist Exception Value: Supplier2.html
and the traceback:
Template-loader postmortem Django tried loading these templates, in this order: Using engine django: django.template.loaders.filesystem.Loader: /home/ubuntu/website/dashboard/templates/dashboard/dashboard2/templates/dashboard2/Supplier2.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/ubuntu/website/customers/templates/Supplier2.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/ubuntu/exo/lib/python3.6/site-packages/django/contrib/auth/templates/Supplier2.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/ubuntu/website/dashboard/templates/Supplier2.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/ubuntu/website/tenantlogin/templates/Supplier2.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/ubuntu/website/uploadfiles/templates/Supplier2.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/ubuntu/exo/lib/python3.6/site-packages/django_tenants/templates/Supplier2.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/ubuntu/exo/lib/python3.6/site-packages/rest_framework/templates/Supplier2.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/ubuntu/exo/lib/python3.6/site-packages/django_tables2/templates/Supplier2.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/ubuntu/website/dashboard2/templates/Supplier2.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/ubuntu/exo/lib/python3.6/site-packages/django/contrib/admin/templates/Supplier2.html (Source does not exist) django.template.loaders.app_directories.Loader: /home/ubuntu/exo/lib/python3.6/site-packages/crispy_forms/templates/Supplier2.html (Source does not exist)
when try specifying /dashboard2/Supplier2.html
I still get the same error in Django:
TemplateDoesNotExist at /Supplier2.html /dashboard2/Supplier2.html
here is what I have in settings.py for templates:
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, "dashboard/templates/dashboard", "dashboard2/templates/dashboard2")], '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', 'django.template.context_processors.i18n' ], }, }, ]
at this point, I don’t know what else to try
Advertisement
Answer
Fix the settings as below:
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, "dashboard/templates/dashboard"), os.path.join(BASE_DIR,"dashboard2/templates/dashboard2")], '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', 'django.template.context_processors.i18n' ], }, }, ]