Hi, pretty new to Django. Django adds auth to my path and that leads to TemplateNotFound issue. My code piece is as below but I am unable to move forward.
*
django.template.loaders.filesystem.Loader : C:\eComm\advanced_django\Practice_1\school\users\templates\auth\user_list.html (Source does not exist)
Whereas the correct path is : \users\templates\user_list.html
From views.py :
class UserListView(ListView):
model = User
queryset = User.objects.all()
From urls.py
urlpatterns = [path("user_list/", UserListView.as_view(), name="user_list"),]
Error :
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\django\template\loader.py", line 47, in select_template
raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
django.template.exceptions.TemplateDoesNotExist: auth/user_list.html
[15/Mar/2022 20:18:13] ?[35;1m"GET /users/user_list/ HTTP/1.1" 500 78938?[0m
Is that the complete error message, or is there more to that message prior to that?
What is the name of the app in which this view exists?
What does your TEMPLATES settings look like?
Complete error messages is as below.
# TemplateDoesNotExist at /users/user_list/
auth/user_list.html
|Request Method:|GET|
| --- | --- |
|Request URL:|http://127.0.0.1:8000/users/user_list/|
|Django Version:|4.0.2|
|Exception Type:|TemplateDoesNotExist|
|Exception Value:|auth/user_list.html|
|Exception Location:|C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\django\template\loader.py, line 47, in select_template|
|Python Executable:|C:\Users\Administrator\AppData\Local\Programs\Python\Python310\python.exe|
|Python Version:|3.10.2|
|Python Path:|['C:\\eComm\\advanced_django\\Practice_1\\school', 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python310\\python310.zip', 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python310\\DLLs', 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python310\\lib', 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python310', 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages']|
|Server time:|Tue, 15 Mar 2022 16:13:04 +0000|
Name of the app is “users” and same is set in the urls.py app_name
TEMPLATES : from the main application’s settings.py : ‘DIRS’: [os.path.join(BASE_DIR, ‘users’)],
This is the call trace as below. I even provided the URL in main apps urls.py. Still face the same issue. I am unable to understand where this “auth” gets injected in the path. Pardon me as I just am trying to learn Django.
C:\eComm\advanced_django\Practice_1\school\users\auth\user_list.html <== Where does “auth” come from?
Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/user_list/
Django Version: 4.0.2
Python Version: 3.10.2
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'classroom.apps.ClassroomConfig',
'users.apps.UsersConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Template loader postmortem
Django tried loading these templates, in this order:
Using engine django:
* django.template.loaders.filesystem.Loader: C:\eComm\advanced_django\Practice_1\school\users\auth\user_list.html (Source does not exist)
* django.template.loaders.app_directories.Loader: C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\admin\templates\auth\user_list.html (Source does not exist)
* django.template.loaders.app_directories.Loader: C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\django\contrib\auth\templates\auth\user_list.html (Source does not exist)
* django.template.loaders.app_directories.Loader: C:\eComm\advanced_django\Practice_1\school\classroom\templates\auth\user_list.html (Source does not exist)
* django.template.loaders.app_directories.Loader: C:\eComm\advanced_django\Practice_1\school\users\templates\auth\user_list.html (Source does not exist)
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\base.py", line 204, in _get_response
response = response.render()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\django\template\response.py", line 105, in render
self.content = self.rendered_content
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\django\template\response.py", line 81, in rendered_content
template = self.resolve_template(self.template_name)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\django\template\response.py", line 63, in resolve_template
return select_template(template, using=self.using)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\django\template\loader.py", line 47, in select_template
raise TemplateDoesNotExist(', '.join(template_name_list), chain=chain)
Exception Type: TemplateDoesNotExist at /user_list/
Exception Value: auth/user_list.html