Django:租户的模板路径问题
Django: issue with template path for tenant
我有一个应用程序,根据其类别,租户可以在 /dashboard/templates/dashboard
或 /dashboard2/templates/dashboard2
.
被定向到应用程序(和模板)
不知何故,对于 dashboard2,Django 找不到该应用程序,它会尝试在 dashboard
.
下找到那些模板
这是一个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)
和错误:
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
和追溯:
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)
当尝试指定 /dashboard2/Supplier2.html
时,我在 Django 中仍然遇到同样的错误:
TemplateDoesNotExist at /Supplier2.html
/dashboard2/Supplier2.html
这是我在 settings.py 中的模板:
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'
],
},
},
]
此时,我不知道还能尝试什么
修改如下设置:
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'
],
},
},
]
我有一个应用程序,根据其类别,租户可以在 /dashboard/templates/dashboard
或 /dashboard2/templates/dashboard2
.
不知何故,对于 dashboard2,Django 找不到该应用程序,它会尝试在 dashboard
.
这是一个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)
和错误:
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
和追溯:
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)
当尝试指定 /dashboard2/Supplier2.html
时,我在 Django 中仍然遇到同样的错误:
TemplateDoesNotExist at /Supplier2.html
/dashboard2/Supplier2.html
这是我在 settings.py 中的模板:
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'
],
},
},
]
此时,我不知道还能尝试什么
修改如下设置:
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'
],
},
},
]