zoukankan      html  css  js  c++  java
  • django踩坑记录

    在django中使用bootstrap4报错:OSError: [WinError 123] 文件名、目录名或卷标语法不正确。: ‘「frozen importlib._bootstrap」‘”

    在aototest/settings.py 中加入如下内容:

    INSTALL_APPS = (
    	#...
    	'bootstrap4',
    	#...
    

    在product_manage.html中:

    # {# Load the tag library #}
    {% load bootstrap4 %}
    
    # {# Load CSS and JavaScript #}
    {% bootstrap_css %}
    {% bootstrap_javascript jquery='full' %}
    
    

    随后访问 http://127.0.0.1:8000/product_manage/
    链接失败。
    查看development server已自动退出,重启server:

    C:UsersJhinAppDataLocalProgramsPythonPython37Scriptsautotest>python manage.py runserver
    Watching for file changes with StatReloader
    Exception in thread django-main-thread:
    Traceback (most recent call last):
      File "C:UsersJhinAppDataLocalProgramsPythonPython37lib	hreading.py", line 926, in _bootstrap_inner
        self.run()
      File "C:UsersJhinAppDataLocalProgramsPythonPython37lib	hreading.py", line 870, in run
        self._target(*self._args, **self._kwargs)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoutilsautoreload.py", line 53, in wrapper
        fn(*args, **kwargs)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangocoremanagementcommands
    unserver.py", line 109, in inner_run
        autoreload.raise_last_exception()
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoutilsautoreload.py", line 76, in raise_last_exception
        raise _exception[1]
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangocoremanagement\__init__.py", line 357, in execute
        autoreload.check_errors(django.setup)()
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoutilsautoreload.py", line 53, in wrapper
        fn(*args, **kwargs)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjango\__init__.py", line 24, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoapps
    egistry.py", line 91, in populate
        app_config = AppConfig.create(entry)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoappsconfig.py", line 90, in create
        module = import_module(entry)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libimportlib\__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 965, in _find_and_load_unlocked
    ModuleNotFoundError: No module named 'bootstrap'
    
    Traceback (most recent call last):
      File "manage.py", line 21, in <module>
        main()
      File "manage.py", line 17, in main
        execute_from_command_line(sys.argv)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangocoremanagement\__init__.py", line 401, in execute_from_command_line
        utility.execute()
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangocoremanagement\__init__.py", line 395, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangocoremanagementase.py", line 328, in run_from_argv
        self.execute(*args, **cmd_options)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangocoremanagementcommands
    unserver.py", line 60, in execute
        super().execute(*args, **options)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangocoremanagementase.py", line 369, in execute
        output = self.handle(*args, **options)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangocoremanagementcommands
    unserver.py", line 95, in handle
        self.run(**options)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangocoremanagementcommands
    unserver.py", line 102, in run
        autoreload.run_with_reloader(self.inner_run, **options)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoutilsautoreload.py", line 599, in run_with_reloader
        start_django(reloader, main_func, *args, **kwargs)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoutilsautoreload.py", line 584, in start_django
        reloader.run(django_main_thread)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoutilsautoreload.py", line 299, in run
        self.run_loop()
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoutilsautoreload.py", line 305, in run_loop
        next(ticker)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoutilsautoreload.py", line 345, in tick
        for filepath, mtime in self.snapshot_files():
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoutilsautoreload.py", line 361, in snapshot_files
        for file in self.watched_files():
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoutilsautoreload.py", line 260, in watched_files
        yield from iter_all_python_module_files()
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoutilsautoreload.py", line 105, in iter_all_python_module_files
        return iter_modules_and_files(modules, frozenset(_error_files))
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libsite-packagesdjango-3.0.8-py3.7.eggdjangoutilsautoreload.py", line 141, in iter_modules_and_files
        resolved_path = path.resolve(strict=True).absolute()
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libpathlib.py", line 1161, in resolve
        s = self._flavour.resolve(self, strict=strict)
      File "C:UsersJhinAppDataLocalProgramsPythonPython37libpathlib.py", line 200, in resolve
        return self._ext_to_normal(_getfinalpathname(s))
    OSError: [WinError 123] 文件名、目录名或卷标语法不正确。: '<frozen importlib._bootstrap>'
    

    百度几天均无果,后重新安装bootstrap

    pip install django-bootstrap4
    

    runserver还是一样的报错。
    重新运行:

    python manage.py migrate
    

    随后runserver成功:

    C:UsersJhinAppDataLocalProgramsPythonPython37Scriptsautotest>python manage.py runserver
    Watching for file changes with StatReloader
    Performing system checks...
    
    System check identified no issues (0 silenced).
    July 13, 2020 - 03:12:05
    Django version 3.0.8, using settings 'autotest.settings'
    Starting development server at http://127.0.0.1:8000/
    Quit the server with CTRL-BREAK.
    [13/Jul/2020 03:12:15] "GET /product_manage/ HTTP/1.1" 200 2399
    
    

    总结为先

    python manage.py migrate
    

    python manage.py runserver
    

    就成功了(不知道为啥,手动狗头)
    截图为证:
    自动化平台demo版
    卡了我几天的坑,记录一下。

    报错:TemplateSyntaxError at /apistep_manage/

    Invalid block tag on line 48: ‘else’, expected ‘empty’ or ‘endfor’. Did you forget to register or load this tag?
    在这里插入图片描述
    几经排查后还是找不到原因,后受文章 传送门 的启发,在if开始时的地方查找,找到问题所在:

    此处少了一个百分号%,添加上之后,报错解决。

    报错:TemplateSyntaxError at /apistep_manage/

    Could not parse the remainder: ‘% if apistep.apistatus == 1 %’ from ‘% if apistep.apistatus == 1 %’

    在这里插入图片描述
    经排查,系此处多了一对花括号,去除一对花括号后,该报错解决。

    报错:Unclosed tag on line 37: ‘for’. Looking for one of: empty, endfor.

    在这里插入图片描述
    后排除问题如下:
    在这里插入图片描述
    最后显示界面如下:
    在这里插入图片描述
    总结:一定要注意百分号空格/百分号是否成对/一对百分号是否写成了两对。。。引以为戒中。。。

    报错:TypeError: bug_manage() missing 1 required positional argument: ‘request’

    在这里插入图片描述
    经排查,系此处括号有问题:
    在这里插入图片描述

    runserver时报错:

    raise RuntimeError(“cryptography is required for sha256_password or caching_sha2_password”)
    RuntimeError: cryptography is required for sha256_password or caching_sha2_password
    原因是没有连接数据库。

    前端界面异常

    搭建测试平台的时候,出现前端一场:
    在这里插入图片描述
    经排查,乃一低级错误:
    在这里插入图片描述
    如图所示,container写到了引号外面(手动狗头),修改后显示正常。
    在这里插入图片描述

  • 相关阅读:
    各种机器学习方法概念
    深入理解拉格朗日乘子法(Lagrange Multiplier) 和KKT条件
    肤色识别
    创建自己的窗口消息
    模糊C均值
    Fisher线性判别
    用遗传算法加强足球游戏的人工智能
    人工智能-遗传算法解决推箱子问题现实
    LBP特征
    VC 制作系统托盘程序实现将窗口最小化到系统托
  • 原文地址:https://www.cnblogs.com/xiaotufei/p/13338431.html
Copyright © 2011-2022 走看看