views.py 774 B

123456789101112131415161718192021222324252627
  1. from django.contrib.auth.forms import UserCreationForm
  2. from django.contrib.auth.views import LoginView
  3. from django.shortcuts import render, redirect
  4. from django.urls import reverse_lazy
  5. from django.views.generic import CreateView
  6. from .models import Product, UserProfile
  7. def index(request):
  8. products = Product.objects.all()[:5]
  9. return render(request, 'index.html', {'products': products})
  10. def products(request):
  11. products = Product.objects.all()
  12. return render(request, 'products.html', {'products': products})
  13. class BBLoginView(LoginView):
  14. template_name = 'login.html'
  15. class RegistrationUserView(CreateView):
  16. model = UserProfile
  17. form_class = UserCreationForm
  18. template_name = 'registration.html'
  19. success_url = reverse_lazy('login')