django實(shí)現(xiàn)后臺(tái)顯示媒體文件
1、在全局settings文件中配置
```MEDIA_URL = ’/media/’MEDIA_ROOT = os.path.join(BASE_DIR, ’media’)
2、 在全局的urls文件中:
from MxShop.settings import MEDIA_ROOT #導(dǎo) 入配置文件中的配置from django.views.static import serve
urlpatterns = [ url(r’^media/(?P<path>.*)$’, serve, {'document_root': MEDIA_ROOT}),]
這樣在后臺(tái)上傳媒體文件就能顯示出來。
補(bǔ)充知識(shí):pycharm中用pyinstaller 打包生成 .exe時(shí)出現(xiàn)typeerror:expected str,bytes or os.path,not None type解決方法
系統(tǒng):win10 64位
錯(cuò)誤提示如下:
Traceback (most recent call last): File 'C:UsersuserDesktopuntitled1venvScriptspyinstaller-script.py', line 11, in <module> load_entry_point(’PyInstaller==3.4’, ’console_scripts’, ’pyinstaller’)() File 'C:UsersuserDesktopuntitled1venvlibsite-packagesPyInstaller__main__.py', line 111, in run run_build(pyi_config, spec_file, **vars(args)) File 'C:UsersuserDesktopuntitled1venvlibsite-packagesPyInstaller__main__.py', line 63, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File 'C:UsersuserDesktopuntitled1venvlibsite- packagesPyInstallerbuildingbuild_main.py', line 838, in main build(specfile, kw.get(’distpath’), kw.get(’workpath’), kw.get(’clean_build’)) File 'C:UsersuserDesktopuntitled1venvlibsite- packagesPyInstallerbuildingbuild_main.py', line 784, in build exec(text, spec_namespace) File '<string>', line 29, in <module> File 'C:UsersuserDesktopuntitled1venvlibsite-packagesPyInstallerbuildingapi.py', line 424, in __init__ strip_binaries=self.strip, upx_binaries=self.upx, File 'C:UsersuserDesktopuntitled1venvlibsite-packagesPyInstallerbuildingapi.py', line 196, in __init__ self.__postinit__() File 'C:UsersuserDesktopuntitled1venvlibsite-packagesPyInstallerbuildingdatastruct.py', line 158, in __postinit__ self.assemble() File 'C:UsersuserDesktopuntitled1venvlibsite-packagesPyInstallerbuildingapi.py', line 273, in assemble pylib_name = os.path.basename(bindepend.get_python_library_path()) File 'C:UsersuserAppDataLocalProgramsPythonPython37libntpath.py', line 214, in basename return split(p)[1] File 'C:UsersuserAppDataLocalProgramsPythonPython37libntpath.py', line 183, in split p = os.fspath(p) TypeError: expected str, bytes or os.PathLike object, not NoneType
解決方法:
在github這個(gè)頁面上https://github.com/Loran425/pyinstaller/tree/14b6e65642e4b07a4358bab278019a48dedf7460
下載所有文件,解壓后找到文件夾PyInstaller里的bindepend.py文件,然后copy替換C:xxxvenvLibsite-packagesPyInstallerdepend里的bindepend.py,其中xxx為你自己電腦上的路徑,不同的個(gè)人電腦路徑可能不太一樣。
然后在pycharm Terminal 運(yùn)行命令:pyinstaller -F xx.py即可。xx為python文件名。
以上這篇django實(shí)現(xiàn)后臺(tái)顯示媒體文件就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. Hybris在idea中debug配置方法詳解2. 在idea中為注釋標(biāo)記作者日期操作3. jsp cookie+session實(shí)現(xiàn)簡(jiǎn)易自動(dòng)登錄4. XPath入門 - XSL教程 - 35. 通過CSS數(shù)學(xué)函數(shù)實(shí)現(xiàn)動(dòng)畫特效6. .NET Core Web APi類庫(kù)內(nèi)嵌運(yùn)行的方法7. .NET6使用ImageSharp實(shí)現(xiàn)給圖片添加水印8. ASP.NET MVC實(shí)現(xiàn)橫向展示購(gòu)物車9. ASP.NET MVC使用Boostrap實(shí)現(xiàn)產(chǎn)品展示、查詢、排序、分頁10. .net如何優(yōu)雅的使用EFCore實(shí)例詳解
