繁体   English   中英

为什么我的异常会给出语法错误

why does my exception give a syntax error

提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供   中文繁体   英文版本   中英对照 版本,有任何建议请联系yoyou2525@163.com。

对于django和python来说,这是一个非常新的网站,我正在做的网站是一个电子商务网站,它有一个购物车应用程序,可以处理views.py文件中的购物车,我具有以下功能:

  def get(self, request):
    try:
        item_id = request.GET.get('item')
        quantity = request.GET.get('qty', 1)
        delete = request.GET.get('delete', 'n')
        cart, is_deleted, cart_item = self._process_cart(item_id, int(quantity), delete, request)
        cart_count = cart.total_count
        request.session['cart_count'] = cart_count
        return Response({'success': True,
         'deleted': is_deleted,
          'count': cart.count,
          'item_total': cart_item.item_total,
          'cart_price': cart.cart_price,
          'cart_count': cart_count}, status=status.HTTP_200_OK)
    except Exception as error:
        print error

它总是给出一个无效的语法错误

 Traceback (most recent call last):
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\utils\autoreload.py", line 225, in wrapper
 fn(*args, **kwargs)
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\core\management\commands\runserver.py", line 117, in 
 inner_run
 self.check(display_num_errors=True)
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\core\management\base.py", line 379, in check
 include_deployment_checks=include_deployment_checks,
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\core\management\base.py", line 366, in _run_checks
 return checks.run_checks(**kwargs)
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\core\checks\registry.py", line 71, in run_checks
 new_errors = check(app_configs=app_configs)
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\core\checks\urls.py", line 13, in check_url_config
 return check_resolver(resolver)
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\core\checks\urls.py", line 23, in check_resolver
 return check_method()
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\urls\resolvers.py", line 396, in check
 for pattern in self.url_patterns:
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\utils\functional.py", line 37, in __get__
 res = instance.__dict__[self.name] = self.func(instance)
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\urls\resolvers.py", line 533, in url_patterns
 patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\utils\functional.py", line 37, in __get__
 res = instance.__dict__[self.name] = self.func(instance)
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\urls\resolvers.py", line 526, in urlconf_module
 return import_module(self.urlconf_name)
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37- 
 32\lib\importlib\__init__.py", line 127, in import_module
 return _bootstrap._gcd_import(name[level:], package, level)
 File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
 File "<frozen importlib._bootstrap>", line 983, in _find_and_load
 File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
 File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
 File "<frozen importlib._bootstrap_external>", line 728, in exec_module
 File "<frozen importlib._bootstrap>", line 219, in 
 _call_with_frames_removed
 File "C:\ecommerce-django-master\src\ecommerce\urls.py", line 15, in 
 <module>
 url(r'^cart/', include('carts.urls')),
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37-32\lib\site- 
 packages\django\urls\conf.py", line 34, in include
 urlconf_module = import_module(urlconf_module)
 File "C:\Users\ADMIN\AppData\Local\Programs\Python\Python37- 
 32\lib\importlib\__init__.py", line 127, in import_module
 return _bootstrap._gcd_import(name[level:], package, level)
 File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
 File "<frozen importlib._bootstrap>", line 983, in _find_and_load
 File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
 File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
 File "<frozen importlib._bootstrap_external>", line 728, in exec_module
 File "<frozen importlib._bootstrap>", line 219, in 
 _call_with_frames_removed
 File "C:\ecommerce-django-master\src\carts\urls.py", line 4, in <module>
 from . import views
 File "C:\ecommerce-django-master\src\carts\views.py", line 56
return Response({'success': True, 'deleted': is_deleted, 'count': 
cart.count, 'item_total': cart_item.item_total, 'cart_price': 
cart.cart_price, 'cart_count':cart_count}, status = status.HTTP_200_OK)
     ^
SyntaxError: invalid syntax

所以我尝试使用if而不是try,但是结果是我的购物车之后无法正常工作,它从未更新过徽章,甚至在下订单后也没有任何东西

问题暂未有回复.您可以查看右边的相关问题.
3 如果不存在,工作的CREATE VIEW会给出语法错误

对于统计报告,我有一个简单的CREATE VIEW脚本,该脚本本身可以工作: 当我在SQL Server 2016上进行开发时,不能保证在客户安装上使用,因此不能使用CREATE或ALTER。 因此,我认为应该将其放入标准的“不存在”中: (无论是否使用BEGIN-END, ...

5 当我运行宏时,为什么Excel会给出“编译错误:语法错误”

我正在尝试为使用下拉列表的工作表创建到PDF宏的打印。 我希望下拉列表中的每个选项都另存为自己的PDF。 这是我的代码: 我的下拉列表从A1开始,尽管我希望PDF从A2开始。 带有下拉列表的单元格是d8 名为“ NewStoreRollout”的单元包含我要保 ...

2019-04-08 19:46:51 1 46   vba
7 代码给出语法错误并给出 KeyboardInterrupt

一家宠物店会在四小时内跟踪客户的购买情况。 商店经理将购买分类为包含狗产品、猫产品、鱼产品或用于不同种类宠物的产品。 她找到。 一种。 83 购买了狗产品 b. 101 购买了猫产品 c. 22 购买了鱼产品 d. 31 购买了一只狗和一只猫的产品 e. 8 购买了一只狗和一个鱼制品 f. ...

2021-02-20 17:04:20 1 32   python
9 SQL语法给出未知的语法错误

我的mysql语句有问题。 基本上,代码在插入时可以完美地工作,但是一旦addnew variable = false并切换为更新,它就会给我一个我无法解决的错误。 编码: procedure Tadddomain.BitBtn2Click(Sender: TObject); Va ...

10 尝试抛出异常会给PHP CLI带来致命错误

我试图在为PHP CLI编写的脚本中throw new Exception(...) 。 这是错误: 这行是指: 这是配置问题还是其他原因引起的? 我之前没有写过任何要与PHP CLI一起使用的东西,因此不确定很多类似这样的事情。 感谢所有帮助。 ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2022 STACKOOM.COM