1、在全局settings文件中配置

```
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

2、 在全局的urls文件中:

from MxShop.settings import MEDIA_ROOT #导 入配置文件中的配置
from django.views.static import serve

urlpatterns = [

 url(r'^media/("document_root": MEDIA_ROOT}),

]

这样在后台上传媒体文件就能显示出来。

补充知识:pycharm中用pyinstaller 打包生成 .exe时出现typeerror:expected str,bytes or os.path,not None type解决方法

系统: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这个页面上https://github.com/Loran425/pyinstaller/tree/14b6e65642e4b07a4358bab278019a48dedf7460

下载所有文件,解压后找到文件夹PyInstaller里的bindepend.py文件,然后copy替换C:\xxx\venv\Lib\site-packages\PyInstaller\depend里的bindepend.py,其中xxx为你自己电脑上的路径,不同的个人电脑路径可能不太一样。

然后在pycharm Terminal 运行命令:pyinstaller -F xx.py即可。xx为python文件名。

以上这篇django实现后台显示媒体文件就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

风云阁资源网 Design By www.bgabc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
风云阁资源网 Design By www.bgabc.com

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?