zoukankan      html  css  js  c++  java
  • SyntaxError Generator expression must be parenthesized

    环境:

    • Windows10
    • python3.7.0
    • Django1.11.15

    异常

    启动Django时抛出以下异常:

    Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0000024D934BDD08>
    Traceback (most recent call last):
      File "C:Python37libsite-packagesdjangoutilsautoreload.py", line 228, in wrapper
        fn(*args, **kwargs)
      File "C:Python37libsite-packagesdjangocoremanagementcommands
    unserver.py", line 116, in inner_run
        autoreload.raise_last_exception()
      File "C:Python37libsite-packagesdjangoutilsautoreload.py", line 251, in raise_last_exception
        six.reraise(*_exception)
      File "C:Python37libsite-packagesdjangoutilssix.py", line 685, in reraise
        raise value.with_traceback(tb)
      File "C:Python37libsite-packagesdjangoutilsautoreload.py", line 228, in wrapper
        fn(*args, **kwargs)
      File "C:Python37libsite-packagesdjango\__init__.py", line 27, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "C:Python37libsite-packagesdjangoapps
    egistry.py", line 85, in populate
        app_config = AppConfig.create(entry)
      File "C:Python37libsite-packagesdjangoappsconfig.py", line 94, in create
        module = import_module(entry)
      File "C:Python37libimportlib\__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:Python37libsite-packagesdjangocontribadmin\__init__.py", line 4, in <module>
        from django.contrib.admin.filters import (
      File "C:Python37libsite-packagesdjangocontribadminfilters.py", line 10, in <module>
        from django.contrib.admin.options import IncorrectLookupParameters
      File "C:Python37libsite-packagesdjangocontribadminoptions.py", line 13, in <module>
        from django.contrib.admin import helpers, widgets
      File "C:Python37libsite-packagesdjangocontribadminwidgets.py", line 152
        '%s=%s' % (k, v) for k, v in params.items(),
        ^
    SyntaxError: Generator expression must be parenthesized
    

    解决方法

    • '%s=%s' % (k, v) for k, v in params.items(),中的后边的逗号去掉就ok了

    Linux下的解决方法

    Linux下启动失败跑抛出异常,和Windows下一样,查看抛出异常的最后一个提示的路径和行号。使用sudo编进该路径下的该py文件,方法同上,保存就ok了

    类似的文件路径

    sudo vi /usr/local/lib/python3.7/site-packages/django/contrib/admin/widgets.py
    

    修改源码

    related_url += '?' + '&amp;'.join(
        '%s=%s' % (k, v) for k, v in params.items(),
    )
    # 修改:
    related_url += '?' + '&amp;'.join(
        '%s=%s' % (k, v) for k, v in params.items()
    )
    
  • 相关阅读:
    海康视频 rtnp转 flv
    生成随机不重复数列表(C#)
    保证应用程序只运行一个实例[c#]
    [C++] C++指针的那些事 常量,变量,指针及指针相关的三个数值
    C#压缩与解压缩流类 GZipStream 的使用
    [C# WinFrom 使用 Google Map] 在地图上画轨迹线
    一个泛型应用示例
    没五笔,不写了
    利用Socket HTTP协议获得HTML代码方法
    Remoting实例(客户端发送信息)
  • 原文地址:https://www.cnblogs.com/linga/p/9705893.html
Copyright © 2011-2022 走看看