Reputation: 169
I have looked at similar posts, but am really struggling with templates and urls.py - at least thats where I think my problem is.
I'm trying to use the default login page that comes with django. I get this error message, I've tried so many things but still cannot not get to work, can some please help?
This is the error message:
TemplateDoesNotExist at /accounts/login/
registration/login.html
Request Method: GET
Request URL: http://134.209.220.170/accounts/login/?next=/timwise/upload/
Django Version: 5.0
Exception Type: TemplateDoesNotExist
Exception Value:
registration/login.html
Exception Location: /usr/local/lib/python3.10/dist-packages/django/template/loader.py, line 47, in select_template
Raised during: django.contrib.auth.views.LoginView
Python Executable: /usr/bin/python3
Python Version: 3.10.12
Python Path:
['/home/django/django_project',
'/usr/bin',
'/usr/lib/python310.zip',
'/usr/lib/python3.10',
'/usr/lib/python3.10/lib-dynload',
'/usr/local/lib/python3.10/dist-packages',
'/usr/lib/python3/dist-packages']
Server time: Wed, 23 Oct 2024 01:53:02 +0000
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: /home/django/django_project/templates/registration/login.html (Source does not exist)
django.template.loaders.app_directories.Loader: /usr/local/lib/python3.10/dist-packages/django/contrib/admin/templates/registration/login.html (Source does not exist)
django.template.loaders.app_directories.Loader: /usr/local/lib/python3.10/dist-packages/django/contrib/auth/templates/registration/login.html (Source does not exist)
this is the template area of my settings.py:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# 'DIRS': [BASE_DIR, "/home/django/django_project/templates"],
'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',
],
},
},
]
this is my class view that is trying to redirect to the default django login page:
class FileUploadView(LoginRequiredMixin, CreateView): #entire class from gemini
model = Files
form_class = FileUploadForm
template_name = 'upload.html' # Create this template file
success_url = reverse_lazy('success') # Define this url in urls.py
def form_valid(self, form):
file = form.save()
filename = file.file.name
msg="file name is good"
print('file loaded successfully')
messages.success(self.request, f"File '{filename}' uploaded successfully!")
return redirect('success', filename=filename, msg=msg) #pass the filename as a url parameter
def form_invalid(self, form):
# Handle form validation errors
messages.error(self.request, "File upload failed. Please check the file and try again.")
return super().form_invalid(form)
this is from my project level urls.py:
from django.urls import path, include
from .views import UploadHighlights, FileUploadView
from django.views.generic import TemplateView
urlpatterns = [
path('upload/', FileUploadView.as_view(), name='upload'), # gemini
path('accounts/', include('django.contrib.auth.urls')),
path('success/<str:filename>/<str:msg>/', TemplateView.as_view(template_name='success.html'), name='success'),]
this is app level urls.py:
from django.urls import path, include
from .views import UploadHighlights, FileUploadView
from django.views.generic import TemplateView
urlpatterns = [
path('upload/', FileUploadView.as_view(), name='upload'), # gemini
path('accounts/', include('django.contrib.auth.urls')),
path('success/<str:filename>/<str:msg>/', TemplateView.as_view(template_name='success.html'), name='success'),]
Upvotes: 0
Views: 77