You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django TypeError修复:'NoneType' object is not iterable(特惠功能异常)

特惠功能访问报错修复方案

问题背景

站点分类功能可正常运行,但访问特惠URL时出现报错。需求为:每个商品可关联分类和/或特惠,支持跳转至特定特惠分类。

相关链接代码:

<a href="{% url 'products' %}?category=acoustic-drumkits" class="dropdown-item">Drumkits</a>

<a href="{% url 'products' %}?special_offers=clearance" class="dropdown-item ">B Stock</a>

错误根源

  1. views.py拼写错误:处理特惠参数时将special_offers误写为speical_offers,导致special_offers变量值为None,执行products.filter(special_offers__name__in=special_offers)时触发TypeError。
  2. HTML拼写错误:特惠链接的查询参数同样存在上述拼写错误。

修复步骤

  • 修正views.py参数获取逻辑:
    找到获取特惠参数的代码行,将request.GET.get('speical_offers')修改为request.GET.get('special_offers'),确保变量能正确获取URL中的参数值。
  • 修正HTML链接参数:
    检查所有特惠跳转链接,确认查询参数名为special_offers,避免拼写错误。
  • 验证修复效果:
    重启服务后访问特惠URL,确认商品过滤逻辑正常执行,不再触发报错。

内容的提问来源于stack exchange,提问作者Zursen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 17:04:57