您好,登录后才能下订单哦!
这篇文章主要讲解了“django怎么实现在后台显示媒体文件的功能”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“django怎么实现在后台显示媒体文件的功能”吧!
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/(?P<path>.*)$', serve, {"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怎么实现在后台显示媒体文件的功能”的内容了,经过本文的学习后,相信大家对django怎么实现在后台显示媒体文件的功能这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。