您好,登錄后才能下訂單哦!
這篇文章主要講解了“django怎么實(shí)現(xiàn)在后臺顯示媒體文件的功能”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“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位
錯(cuò)誤提示如下:
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)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對django怎么實(shí)現(xiàn)在后臺顯示媒體文件的功能這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。