django實(shí)現(xiàn)后臺顯示媒體文件
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}), ]
這樣在后臺上傳媒體文件就能顯示出來。
補(bǔ)充知識:pycharm中用pyinstaller 打包生成 .exe時(shí)出現(xiàn)typeerror:expected str,bytes or os.path,not None type解決方法
系統(tǒng):win10 64位
錯誤提示如下:
Traceback (most recent call last): File "C:\Users\user\Desktop\untitled1\venv\Scripts\pyinstaller-script.py", line 11, in <module> load_entry_point('PyInstaller==3.4', 'console_scripts', 'pyinstaller')() File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\__main__.py", line 111, in run run_build(pyi_config, spec_file, **vars(args)) File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "C:\Users\user\Desktop\untitled1\venv\lib\site- packages\PyInstaller\building\build_main.py", line 838, in main build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File "C:\Users\user\Desktop\untitled1\venv\lib\site- packages\PyInstaller\building\build_main.py", line 784, in build exec(text, spec_namespace) File "<string>", line 29, in <module> File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\building\api.py", line 424, in __init__ strip_binaries=self.strip, upx_binaries=self.upx, File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\building\api.py", line 196, in __init__ self.__postinit__() File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__ self.assemble() File "C:\Users\user\Desktop\untitled1\venv\lib\site-packages\PyInstaller\building\api.py", line 273, in assemble pylib_name = os.path.basename(bindepend.get_python_library_path()) File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\ntpath.py", line 214, in basename return split(p)[1] File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\ntpath.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:\xxx\venv\Lib\site-packages\PyInstaller\depend里的bindepend.py,其中xxx為你自己電腦上的路徑,不同的個(gè)人電腦路徑可能不太一樣。
然后在pycharm Terminal 運(yùn)行命令:pyinstaller -F xx.py即可。xx為python文件名。
以上這篇django實(shí)現(xiàn)后臺顯示媒體文件就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
python實(shí)現(xiàn)密碼驗(yàn)證合格程序的思路詳解
這篇文章主要介紹了python實(shí)現(xiàn)密碼驗(yàn)證合格程序的思路詳解,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06python調(diào)用opencv實(shí)現(xiàn)貓臉檢測功能
這篇文章主要介紹了python調(diào)用opencv實(shí)現(xiàn)貓臉檢測功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01python3?flask使用連接池連接數(shù)據(jù)庫實(shí)例
這篇文章主要為大家介紹了python3?flask使用連接池連接數(shù)據(jù)庫實(shí)例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08python實(shí)現(xiàn)批量按比例縮放圖片效果
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)批量按比例縮放圖片效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03python數(shù)據(jù)化運(yùn)營的重要意義
在本篇文章里小編給大家分享的是關(guān)于python數(shù)據(jù)化運(yùn)營的重要意義,有興趣的朋友們可以學(xué)習(xí)下。2019-11-11通過python繪制華強(qiáng)買瓜的字符畫視頻的步驟詳解
要把華強(qiáng)賣瓜做成字符視頻大概分為三步,通過讀取視頻,把每一幀轉(zhuǎn)為字符畫,接著把字符畫表現(xiàn)出來,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2021-11-11