Friday, June 11, 2021

Re: IndexError at /

The backtrace is pretty clear..

Here's the import part: 
 File "C:\Users\GEMINI INNOVATIONS\Documents\WEB DEV TUTOR FULL STACK\django_project_boilerplate-master\ECOMMERCE\core\templatetags\cart_template_tags.py", line 13, in cart_item_count return qs[0].items.count() 

"qs" is probably an empty list and you are trying access the 1st item via qs[0]

I'd consider posting future questions not in all caps. Really weird post dude. 


On Fri, Jun 11, 2021 at 2:14 PM Tayo Akinnayajo <tayoakinnayajo@gmail.com> wrote:
PLS IM WORKING ON THIS CAN ANYONE HELP FIX THE ERROR

Environment: Request Method: GET Request URL: http://127.0.0.1:8000/ Django Version: 3.1.4 Python Version: 3.9.0 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'allauth', 'allauth.account', 'allauth.socialaccount', 'core', 'crispy_forms', 'django_countries'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware'] Template error: In template C:\Users\GEMINI INNOVATIONS\Documents\WEB DEV TUTOR FULL STACK\django_project_boilerplate-master\ECOMMERCE\templates\navbar.html, error at line 41 list index out of range 31 : <li class="nav-item"> 32 : <a class="nav-link waves-effect" href="/checkout" target="_blank">Checkout</a> 33 : </li> --> 34 : </ul> 35 : 36 : <!-- Right --> 37 : <ul class="navbar-nav nav-flex-icons"> 38 : {% if request.user.is_authenticated %} 39 : <li class="nav-item"> 40 : <a href="{% url 'core:order-summary' %}" class="nav-link waves-effect"> 41 : <!-- <span class="badge red z-depth-1 mr-1"> {{ request.user | cart_item_count }} </span> --> 42 : <i class="fas fa-shopping-cart"></i> 43 : <span class="clearfix d-none d-sm-inline-block"> Cart </span> 44 : </a> 45 : </li> 46 : <li class="nav-item"> 47 : <a class="nav-link waves-effect" href="{% url 'account_logout' %}"> 48 : <span class="clearfix d-none d-sm-inline-block"> Logout </span> 49 : </a> 50 : </li> 51 : {% else %} Traceback (most recent call last): File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner response = get_response(request) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 202, in _get_response response = response.render() File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\response.py", line 105, in render self.content = self.rendered_content File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\response.py", line 83, in rendered_content return template.render(context, self._request) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 61, in render return self.template.render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 170, in render return self._render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 162, in _render return self.nodelist.render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 938, in render bit = node.render_annotated(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 905, in render_annotated return self.render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\loader_tags.py", line 150, in render return compiled_parent._render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 162, in _render return self.nodelist.render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 938, in render bit = node.render_annotated(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 905, in render_annotated return self.render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\loader_tags.py", line 192, in render return template.render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 172, in render return self._render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 162, in _render return self.nodelist.render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 938, in render bit = node.render_annotated(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 905, in render_annotated return self.render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\loader_tags.py", line 53, in render result = self.nodelist.render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 938, in render bit = node.render_annotated(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 905, in render_annotated return self.render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\defaulttags.py", line 312, in render return nodelist.render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 938, in render bit = node.render_annotated(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 905, in render_annotated return self.render(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 988, in render output = self.filter_expression.resolve(context) File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 698, in resolve new_obj = func(obj, *arg_vals) File "C:\Users\GEMINI INNOVATIONS\Documents\WEB DEV TUTOR FULL STACK\django_project_boilerplate-master\ECOMMERCE\core\templatetags\cart_template_tags.py", line 13, in cart_item_count return qs[0].items.count() File "C:\Users\GEMINI INNOVATIONS\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\query.py", line 325, in __getitem__ return qs._result_cache[0] Exception Type: IndexError at / Exception Value: list index out of range

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f86dee3b-c064-4ba2-9534-e3822d9cd7een%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF-Y%3De6zX4182wRvphDxnRSezd1-biyL6S%3Dvr8%3D4M7sc9rSZ2A%40mail.gmail.com.

No comments:

Post a Comment