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:\Users\Jhin\AppData\Local\Programs\Python\Python37\Scripts\autotest>python manage.py runserver

Watching for file changes with StatReloader

Exception in thread django-main-thread:

Traceback (most recent call last):

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner

    self.run()

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\threading.py", line 870, in run

    self._target(*self._args, **self._kwargs)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\utils\autoreload.py", line 53, in wrapper

    fn(*args, **kwargs)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\core\management\commands\runserver.py", line 109, in inner_run

    autoreload.raise_last_exception()

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\utils\autoreload.py", line 76, in raise_last_exception

    raise _exception[1]

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\core\management\__init__.py", line 357, in execute

    autoreload.check_errors(django.setup)()

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\utils\autoreload.py", line 53, in wrapper

    fn(*args, **kwargs)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\__init__.py", line 24, in setup

    apps.populate(settings.INSTALLED_APPS)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\apps\registry.py", line 91, in populate

    app_config = AppConfig.create(entry)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\apps\config.py", line 90, in create

    module = import_module(entry)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\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 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:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\core\management\__init__.py", line 401, in execute_from_command_line

    utility.execute()

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\core\management\__init__.py", line 395, in execute

    self.fetch_command(subcommand).run_from_argv(self.argv)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\core\management\base.py", line 328, in run_from_argv

    self.execute(*args, **cmd_options)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\core\management\commands\runserver.py", line 60, in execute

    super().execute(*args, **options)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\core\management\base.py", line 369, in execute

    output = self.handle(*args, **options)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\core\management\commands\runserver.py", line 95, in handle

    self.run(**options)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\core\management\commands\runserver.py", line 102, in run

    autoreload.run_with_reloader(self.inner_run, **options)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\utils\autoreload.py", line 599, in run_with_reloader

    start_django(reloader, main_func, *args, **kwargs)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\utils\autoreload.py", line 584, in start_django

    reloader.run(django_main_thread)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\utils\autoreload.py", line 299, in run

    self.run_loop()

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\utils\autoreload.py", line 305, in run_loop

    next(ticker)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\utils\autoreload.py", line 345, in tick

    for filepath, mtime in self.snapshot_files():

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\utils\autoreload.py", line 361, in snapshot_files

    for file in self.watched_files():

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\utils\autoreload.py", line 260, in watched_files

    yield from iter_all_python_module_files()

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\utils\autoreload.py", line 105, in iter_all_python_module_files

    return iter_modules_and_files(modules, frozenset(_error_files))

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\site-packages\django-3.0.8-py3.7.egg\django\utils\autoreload.py", line 141, in iter_modules_and_files

    resolved_path = path.resolve(strict=True).absolute()

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\pathlib.py", line 1161, in resolve

    s = self._flavour.resolve(self, strict=strict)

  File "C:\Users\Jhin\AppData\Local\Programs\Python\Python37\lib\pathlib.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:\Users\Jhin\AppData\Local\Programs\Python\Python37\Scripts\autotest>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版](https://img-blog.csdnimg.cn/20200713032254965.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2MTkwNjUz,size_16,color_FFFFFF,t_70)

卡了我几天的坑,记录一下。

### 报错:

TemplateSyntaxError at /apistep_manage/

Invalid block tag on line 48: 'else', expected 'empty' or 'endfor'. Did you forget to register or load this tag?

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200713143236493.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2MTkwNjUz,size_16,color_FFFFFF,t_70)

几经排查后还是找不到原因,后受文章 [传送门](https://blog.csdn.net/sddr_circle/article/details/80510726) 的启发,在if开始时的地方查找,找到问题所在:

![](https://img-blog.csdnimg.cn/20200713143604829.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2MTkwNjUz,size_16,color_FFFFFF,t_70)

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

### 报错:TemplateSyntaxError at /apistep_manage/

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

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200713143901824.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2MTkwNjUz,size_16,color_FFFFFF,t_70)

经排查,系此处多了一对花括号,去除一对花括号后,该报错解决。

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

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200713145704985.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2MTkwNjUz,size_16,color_FFFFFF,t_70)

后排除问题如下:

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200713145836319.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2MTkwNjUz,size_16,color_FFFFFF,t_70)

最后显示界面如下:

![在这里插入图片描述](https://img-blog.csdnimg.cn/2020071315003824.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2MTkwNjUz,size_16,color_FFFFFF,t_70)

总结:**一定要注意百分号空格/百分号是否成对/一对百分号是否写成了两对。。。引以为戒中。。。**

### 报错:TypeError: bug_manage() missing 1 required positional argument: 'request'

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200714080704604.png)

经排查,系此处括号有问题:

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200714080742555.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2MTkwNjUz,size_16,color_FFFFFF,t_70)

### runserver时报错:

raise RuntimeError("cryptography is required for sha256_password or caching_sha2_password")

RuntimeError: cryptography is required for sha256_password or caching_sha2_password

原因是没有连接数据库。

### 前端界面异常

搭建测试平台的时候,出现前端一场:

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200714195700512.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2MTkwNjUz,size_16,color_FFFFFF,t_70)

经排查,乃一低级错误:

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200714195754329.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2MTkwNjUz,size_16,color_FFFFFF,t_70)

如图所示,container写到了引号外面(手动狗头),修改后显示正常。

![在这里插入图片描述](https://img-blog.csdnimg.cn/20200714195903630.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM2MTkwNjUz,size_16,color_FFFFFF,t_70)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,193评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,306评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,130评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,110评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,118评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,085评论 1 295
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,007评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,844评论 0 273
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,283评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,508评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,667评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,395评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,985评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,630评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,797评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,653评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,553评论 2 352