Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram: / ky.emrah
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!django after submit login info, does not lead to intended detail view page
I don't know what to do here after a few days of trying different ideas. After I submit the the prop login email and password, the page does not do anything. It just says "Invalid password". I am not sure my login view is connected to the sqllite. I am thinking my mistake is where the login view file, but not sure. I also use chatgpt to see if it can identify where the mistake is, but it didn't come up with anything. If anyone can point me where I need to adjust, would be much appricated. If I go to the address of the http://127.0.0.1:8000/user/2/, then, the page shows correctly. Unfortunately, the codes are long.
sqllite
http://127.0.0.1:8000/user/2/
Here are all the codes:
views.py:
import random
from django.shortcuts import render
from django.views.generic import (ListView, DetailView)
from django.views.decorators.csrf import csrf_exempt
from .models import CustomUser, Events
from rest_framework.views import APIView
from .serializers import CustomUserSerializer, EventsSerializer
from rest_framework.response import Response
from rest_framework import status
from rest_framework.renderers import TemplateHTMLRenderer
from django.contrib.auth import authenticate, login
from django.contrib import messages
from django.shortcuts import redirect, render
from django.urls import reverse
from .models import CustomUser # Assuming CustomUser is your user model
def index(request):
return render(request, "users_application/index.html", {})
def user_detail(request, id):
user = CustomUser.objects.get(id = id)
events = user.events_set.all()
return render(request, "users_application/user_detail.html", {'user': user})
Define a view function for the login page
def user_login(request):
if request.method == "POST":
email = request.POST.get('email')
password = request.POST.get('password')
if not CustomUser.objects.filter(email=email).exists():
messages.error(request, 'Invalid Email')
return redirect('login')
user = authenticate(request, username=email, password=password)
if user is None:
messages.error(request, "Invalid Password")
return redirect('login')
else:
login(request, user)
Redirect to the user's detail page after login
return redirect('user-detail', id=user.id)
return render(request, 'users_application/login.html')
class CustomUserAPIView(APIView):
def get(self, request):
users = CustomUser.objects.all()
serializer = CustomUserSerializer(users, many=True)
return Response(serializer.data)
class CustomUserDetailView(APIView):
renderer_classes = [TemplateHTMLRenderer]
template_name = 'users_application/user_detail.html' # Create this template
def get_object(self, id):
try:
return CustomUser.objects.get(id=id)
except CustomUser.DoesNotExist:
raise Http404
def get(self, request, id=None):
if id:
user = self.get_object(id)
serializer = CustomUserSerializer(user)
return Response({'user': serializer.data})
else:
users = CustomUser.objects.all()
serializer = CustomUserSerializer(users, many=True)
return Response({'users': serializer.data})
import random
from django.shortcuts import render
from django.views.generic import (ListViSource of the question:
https://stackoverflow.com/questions/7...
Question and source license information:
https://meta.stackexchange.com/help/l...
https://stackoverflow.com/
Информация по комментариям в разработке