I downloaded a free template and now I’m trying to make some functions. It has class-based functions. And now I’m trying to make login function and it shows Invalid template name in 'extends' tag: ". Got this from the 'layout_path' variable.
views.py
from web_project.template_helpers.theme import TemplateHelper
from django.views.generic import TemplateView
from web_project import TemplateLayout
class AuthView(TemplateView):
def get_context_data(self, **kwargs):
context = TemplateLayout.init(self, super().get_context_data(**kwargs))
context.update(
{
"layout_path": TemplateHelper.set_layout("layout_blank.html", context),
}
)
return context
class LoginView(AuthView):
template_name = 'auth_login_basic.html'
def get(self, request):
return render(request, self.template_name)
def post(self, request):
username = request.POST.get("username")
password = request.POST.get("password")
users = User.objects.filter(username=username)
if len(users):
for user in users:
if password == user.password:
request.session['login_info'] = {'username': user.username, 'userrole': user.userrole}
print(1)
return redirect('/dashboard/')
else:
warn = "Invalid credentials"
messages.success(request, f'{warn}')
return redirect("/auth/login/")
if users is None:
warn = "Invalid credentials"
messages.success(request, f'{warn}')
return redirect('/auth/login/')
else:
return redirect("/dashboard/")
urls.py
from .views import *
urlpatterns = [
path("auth/login/", LoginView.as_view(), name="auth-login-basic"),
]
The template already has this url which is working. It just renders the template. So how about if I add the above login function? I’m a little lost here. I don’t know how to solve this one, it’s my first time using class-based function.
path("auth/login/", AuthView.as_view(template_name="auth_login_basic.html"), name="auth-login-basic")