gpt4 book ai didi

python - Django模板错误 "TemplateDoesNotExist at"

转载 作者:行者123 更新时间:2023-12-01 08:27:47 28 4
gpt4 key购买 nike

我可以使用“py manage.py runserver”运行我的服务器,不会出现任何错误,然后我的登录页面出现,我登录到系统,当我单击该页面中的 customer_list 链接时,主欢迎页面会显示给我一个错误如下。

错误

TemplateDoesNotExist at /clist
customer_list
Request Method: GET
Request URL: http://127.0.0.1:8000/clist
Django Version: 2.0.2
Exception Type: TemplateDoesNotExist
Exception Value:
customer_list

Template-loader postmortem
Django tried loading these templates, in this order:

Using engine django:

django.template.loaders.filesystem.Loader: D:\project\dysapp\templates\customer_list (Source does not exist)
django.template.loaders.app_directories.Loader: D:\project\dysapp\templates\customer_list (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\cenk.adalan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\admin\templates\customer_list (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\cenk.adalan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\auth\templates\customer_list (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\cenk.adalan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django_tables2\templates\customer_list (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Users\cenk.adalan\AppData\Local\Programs\Python\Python37-32\lib\site-packages\import_export\templates\customer_list (Source does not exist)

Settings.py - 模板配置

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

登录主页后,我单击“customer_list”处的此链接并收到错误

      {% if user.is_authenticated %}
<p></p>
{% if perms.dysapp.add_bloodtype %}

<li class="passive"><a href="{% url "customer_list" %}"> <i class="fa fa-link"></i> <span>test2</span></a></li>
<li class="passive"><a href="{% url "login" %}"> <i class="fa fa-link"></i> <span>test</span></a></li>

customer_link.html

{% extends 'ltebase.html' %}
{% block title %}Danışanlar{% endblock %}

{% block content %}

{% for customer in object_list %}
<li>{{ customer.name }}</li>
{% empty %}
<li>No customer exists.</li>
{% endfor %}
{% endblock %}

views.py

from django.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm
from django.contrib.auth.decorators import login_required
from django.http import HttpResponse
from .models import Customer
from django.urls import reverse_lazy

def CustomerList(request, template_name='customer/customer_list.html'):
customer = Customer.objects.all()
data = {}
data['object_list'] = customer
return render(request, template_name, data)

url.py

from django.contrib import admin
from django.urls import path
from django.conf.urls import include, url
from django.conf import settings
from django.views.generic.base import TemplateView
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls.static import static
from django.contrib.auth import views as auth_views
from dysapp.views import main_view, ltebase_view, CustomerList

admin.autodiscover()

urlpatterns = [

path('sapbca_/', admin.site.urls),
# url(r'^admin/', admin.site.urls),
path('', include('django.contrib.auth.urls'), name='login'),
url(r'^$', auth_views.login, name='login'),
url(r'^main/', main_view, name='main'),
url(r'^ltebase/', ltebase_view, name='ltebase'),
path('clist', CustomerList, name='customer_list')
]

最佳答案

您需要修改此

def CustomerList(request):
...
return render(request, 'customer/customer_list.html', data)

关于python - Django模板错误 "TemplateDoesNotExist at",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54110836/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com