'What is if 'admin' in request.path
I followed YouTube Django E-commerce video, I did exactly the same as the tutorial.
But I found some difficulty in certain code.
CONTEXT_PROCESSORS.PY
from .models import cart,cartitem
from .views import getcartid
def counter(request):
cart_counter=0
**if 'admin' in request.path:**
return {}
else:
try:
cart1=cart.objects.filter(cartid=getcartid(request))
cart_items=cartitem.objects.all().filter(basket=cart1[:1]) from 1
for cart_item in cart_items:
cart_counter += cart_item.quantity
except cart.DoesNotExist:
cart_counter=0
return dict(cart_counter=cart_counter)
Can someone explain for me what is if 'admin' in request.path, then return {}?
Solution 1:[1]
It check that the requested user is an admin or not: you can check by this code:
if request.user.is_admin or is_staff or is_superuser from this you can check one thing and return blank dict
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sibtain |
