在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)