django实现后台显示媒体文件

作者:zhangliang_852469 时间:2023-07-26 15:03:23 

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文件名。

来源:https://blog.csdn.net/weixin_39944891/article/details/91969333

标签:django,后台,媒体文件
0
投稿

猜你喜欢

  • python2.7删除文件夹和删除文件代码实例

    2023-06-02 14:41:17
  • 解决TensorFlow程序无限制占用GPU的方法

    2021-11-22 13:13:44
  • python快速排序的实现及运行时间比较

    2022-11-30 20:41:27
  • 在Django中创建动态视图的教程

    2021-09-25 09:17:28
  • 提高CSS代码的可读性

    2008-05-11 18:59:00
  • TensorFlow的环境配置与安装方法

    2022-10-29 12:23:19
  • NopCommerce架构分析之(六)自定义RazorViewEngine和WebViewPage

    2024-05-03 15:31:10
  • 使用cmd命令行窗口操作SqlServer的方法

    2024-01-17 06:13:13
  • Oracle相关组件版本信息的介绍

    2023-07-14 09:19:53
  • python+selenium+chrome批量文件下载并自动创建文件夹实例

    2022-09-14 09:56:42
  • djang常用查询SQL语句的使用代码

    2022-04-27 02:59:51
  • python实现时间o(1)的最小栈的实例代码

    2021-08-01 15:24:42
  • 扩展性很好的一个分页存储过程分享

    2011-11-03 17:04:16
  • Python Tornado框架轻松写一个Web应用的全过程

    2022-05-10 10:38:36
  • 推荐系统MostPopular算法的Python实现方式

    2022-04-21 14:44:24
  • python 使用csv模块读写csv格式文件的示例

    2021-04-24 15:58:28
  • Python3中常用的处理时间和实现定时任务的方法的介绍

    2022-05-13 09:25:25
  • CSS 超链接图标规范 V1.0

    2007-12-28 12:05:00
  • asp正则表达式详细说明

    2008-10-23 16:23:00
  • 利用python和ffmpeg 批量将其他图片转换为.yuv格式的方法

    2023-07-27 11:51:43
  • asp之家 网络编程 m.aspxhome.com