urls.py:
def shopgrid(request, proname=None):
products = Product.objects.all()
categories = Categories.objects.all()
recent_products = Product.objects.order_by('-date')[0:3]
if proname != None:
products = Product.objects.filter(categorie__title=proname)
if request.method == "GET":
recent = request.GET.get('val')
amount = request.GET.get('amount')
print('This is amount--->',amount)
if recent == 'name':
products = Product.objects.order_by('name')
if recent == 'price':
products = Product.objects.order_by('-price')
if 'val' in request.GET:
check_values = request.GET.getlist('val')
first_element=check_values[0]
last_element=check_values[-1]
fe = first_element[0:4]
le = last_element[-4:]
min_price = int(fe)
max_price = int(le)
products = Product.objects.filter(price__range=(min_price, max_price))
print(products)
context={'p':products, 'rp':recent_products, 'cat':categories}
return render(request, 'cart/shop-grid.html', context)
urls.py:
urlpatterns = [
path('', views.index, name="index"),
path('shopgrid/', views.shopgrid, name="shopgrids"),
path('shopgrid/<str:proname>/', views.shopgrid, name="shopgrid"),
path('cat_sort/<str:proname>/', views.cat_sort, name="cat_sort"),
]
ОШИБКА:
**Reverse for 'shopgrid' with no arguments not found. 1 pattern(s) tried: ['shopgrid/(?P<proname>[^/]+)/$']**
<form id="priceform" action="**{% url 'shopgrid' %}**" method="GET">
{% csrf_token %}
<input type="text" id="amount" name="amount" placeholder="Add Your Price">
</form>
def shopgrid (запрос, proname = Нет ): proname - необязательный параметр. Вопрос в том, как записать необязательный параметр в шаблон Jinja. Я уже пишу имя = None, но я столкнулся только с ошибкой HTML