Harmony/main/views.py

42 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import json
from django.shortcuts import render,get_object_or_404
from django.http import HttpResponse, JsonResponse
from .models import Category, Product
from cart.forms import CartAddProductForm
def home(request):
# Ваш код для отображения главной страницы
return render(request, 'main/base.html')
def product_list(request, category_slug=None):
category = None
categories = Category.objects.all()
products = Product.objects.filter(available=True)
if category_slug:
category = get_object_or_404(Category,
slug=category_slug)
products = products.filter(category=category)
return render(request,'main/product/list.html',
{'category': category,
'categories': categories,
'products': products})
def product_detail(request, id, slug):
product = get_object_or_404(Product,
id=id,
slug=slug,
available=True)
cart_product_form = CartAddProductForm()
return render(request,
'main/product/detail.html',
{'product': product,
'cart_product_form': cart_product_form})
# Функция для страницы "О нас"
def about(request):
return render(request, 'main/about.html')
def callback(request):
return render(request,'main/callback.html')