django踩坑記錄


在django中使用bootstrap4報錯:OSError: [WinError 123] 文件名锨用、目錄名或卷標語法不正確。: ‘「frozen importlib._bootstrap」‘”

在aototest/settings.py 中加入如下內(nèi)容:


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

總結(jié)為先

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)

卡了我?guī)滋斓目佑8颍涗浺幌隆?/p>

### 報錯:

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)

幾經(jīng)排查后還是找不到原因,后受文章 [傳送門](https://blog.csdn.net/sddr_circle/article/details/80510726) 的啟發(fā)剑鞍,在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)

經(jīng)排查,系此處多了一對花括號光戈,去除一對花括號后哪痰,該報錯解決遂赠。

### 報錯: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)

總結(jié):**一定要注意百分號空格/百分號是否成對/一對百分號是否寫成了兩對。晌杰。跷睦。引以為戒中。乎莉。送讲。**

### 報錯:TypeError: bug_manage() missing 1 required positional argument: 'request'

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

經(jīng)排查,系此處括號有問題:

![在這里插入圖片描述](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

原因是沒有連接數(shù)據(jù)庫惋啃。

### 前端界面異常

搭建測試平臺的時候哼鬓,出現(xiàn)前端一場:

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

經(jīng)排查,乃一低級錯誤:

![在這里插入圖片描述](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)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末绒瘦,一起剝皮案震驚了整個濱河市称簿,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌惰帽,老刑警劉巖憨降,帶你破解...
    沈念sama閱讀 212,383評論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件策添,死亡現(xiàn)場離奇詭異咐容,居然都是意外死亡,警方通過查閱死者的電腦和手機凹嘲,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,522評論 3 385
  • 文/潘曉璐 我一進店門呜魄,熙熙樓的掌柜王于貴愁眉苦臉地迎上來悔叽,“玉大人,你說我怎么就攤上這事爵嗅〗颗欤” “怎么了?”我有些...
    開封第一講書人閱讀 157,852評論 0 348
  • 文/不壞的土叔 我叫張陵睹晒,是天一觀的道長趟庄。 經(jīng)常有香客問我,道長伪很,這世上最難降的妖魔是什么岔激? 我笑而不...
    開封第一講書人閱讀 56,621評論 1 284
  • 正文 為了忘掉前任,我火速辦了婚禮是掰,結(jié)果婚禮上虑鼎,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好炫彩,可當我...
    茶點故事閱讀 65,741評論 6 386
  • 文/花漫 我一把揭開白布匾七。 她就那樣靜靜地躺著,像睡著了一般江兢。 火紅的嫁衣襯著肌膚如雪昨忆。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,929評論 1 290
  • 那天杉允,我揣著相機與錄音邑贴,去河邊找鬼。 笑死叔磷,一個胖子當著我的面吹牛拢驾,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播改基,決...
    沈念sama閱讀 39,076評論 3 410
  • 文/蒼蘭香墨 我猛地睜開眼繁疤,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了秕狰?” 一聲冷哼從身側(cè)響起稠腊,我...
    開封第一講書人閱讀 37,803評論 0 268
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎鸣哀,沒想到半個月后架忌,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,265評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡我衬,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,582評論 2 327
  • 正文 我和宋清朗相戀三年鳖昌,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片低飒。...
    茶點故事閱讀 38,716評論 1 341
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖懂盐,靈堂內(nèi)的尸體忽然破棺而出褥赊,到底是詐尸還是另有隱情,我是刑警寧澤莉恼,帶...
    沈念sama閱讀 34,395評論 4 333
  • 正文 年R本政府宣布拌喉,位于F島的核電站,受9級特大地震影響俐银,放射性物質(zhì)發(fā)生泄漏尿背。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 40,039評論 3 316
  • 文/蒙蒙 一捶惜、第九天 我趴在偏房一處隱蔽的房頂上張望田藐。 院中可真熱鬧,春花似錦、人聲如沸汽久。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,798評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽景醇。三九已至臀稚,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間三痰,已是汗流浹背吧寺。 一陣腳步聲響...
    開封第一講書人閱讀 32,027評論 1 266
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留散劫,地道東北人稚机。 一個月前我還...
    沈念sama閱讀 46,488評論 2 361
  • 正文 我出身青樓,卻偏偏與公主長得像舷丹,于是被迫代替她去往敵國和親抒钱。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 43,612評論 2 350