zoukankan      html  css  js  c++  java
  • django源码bug解决方案

    django源码bug解决方案

        File "D:	oolpythonvirtualenvxxxlibsite-packagesdjangodbackendsmysqloperations.py", line 146, in last_executed_query  
        query = query.decode(errors='replace')
    AttributeError: 'str' object has no attribute 'decode'
    

    1 修改源码

    # 点到最后一条报错信息的路径
    # 将query = query.decode(errors='replace')中的decode改为encode
    

    2 修改配置

    debug为False时django项目能正常使用

    DEBUG = True
    # DEBUG = False
    

    3 猴子补丁

    在django项目入口处:manage.py中加入猴子补丁

    替换报错的函数

    def monkey_patch_last_executed_query():
        def last_executed_query(self, cursor, sql, params):
            query = getattr(cursor, '_executed', None)
            if query is not None:
                query = query.encode(errors='replace')
            return query
        DatabaseOperations.last_executed_query = last_executed_query
    
    import os
    import sys
    
    from django.db.backends.mysql.operations import DatabaseOperations
    
    
    def monkey_patch_last_executed_query():
        def last_executed_query(self, cursor, sql, params):
            query = getattr(cursor, '_executed', None)
            if query is not None:
                query = query.encode(errors='replace')
            return query
        DatabaseOperations.last_executed_query = last_executed_query
    
    
    def main():
        os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'xxx.settings')
        try:
            from django.core.management import execute_from_command_line
        except ImportError as exc:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            ) from exc
    
        monkey_patch_last_executed_query()
        execute_from_command_line(sys.argv)
    
    
    if __name__ == '__main__':
        main()
    
    
  • 相关阅读:
    页面布局
    导航栏nav的小例子
    块级元素和行内元素
    line-height的理解
    百度地图折线/线段点击不生效
    window系统上生成iosapp并且上架APPstore流程
    上架APPstore
    iOS证书(.p12)、描述文件(.mobileprovision)申请和HBuider打包及注意事项
    在vmware上安装mac os的虚拟机
    hbuilder X 使用苹果手机(ios)进行真机调试
  • 原文地址:https://www.cnblogs.com/achai222/p/14140031.html
Copyright © 2011-2022 走看看