django实现后台显示媒体文件
作者:zhangliang_852469 发布时间:2023-07-26 15:03:23
标签: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文件名。
来源:https://blog.csdn.net/weixin_39944891/article/details/91969333


猜你喜欢
- 在pycharm使用过程中,对于每次新建文件的编码格式和关于代码编写者的一些个人信息快捷填写,方法如下:1.打开pycharm,选择File
- 这篇论坛文章(赛迪网技术社区)根据网友的个人实践扼要的讲解了将MySQL 5.0下的数据导入到MySQL 3.23中的具体方法及步骤,详细内
- 问题:1.一个销售系统,设有各级代理商,每个代理商的表是这样设计的 数据库结构表1: 代理商资料表[id]
- [mysql]replace的用法(替换某字段部分内容)[mysql]replace的用法1.replace into  
- 首先想到的就是contains,contains用法如下:select * from students where contains(add
- 登陆流程图:代码实现:#-*- coding=utf-8 -*-import os,sys,getpass'''us
- 根据用户的权限,展示不同的菜单页。知识点路由守卫(使用了前置守卫):根据用户角色判断要添加的路由vuex:保存动态添加的路由难点每次路由发生
- 使用场景一:如果在一张表中ManayTOManay字段关联的是自身,也就是出项这样的代码:ManyToManyField(self)那么,你
- (1)方法一、直接用a标签的href+数据库中文件地址,即可下载。缺点:word excel是直接弹框下载,对于image txt 等文件的
- 前言XPath,全称XML Path Language,即XML路径语言,它是一门在XML文档中查找信息的语言,它最初是用来搜寻XML文档的
- 网上下载的 pdf 学习资料有一些会带有水印,非常影响阅读。比如下面的图片就是在 pdf 文件上截取出来的。安装模块PIL:Python I
- Nocalhost是一种开发者工具,支持针对Kubernetes应用程序进行调试和部署。使用Nocalhost进行Python开发需要完成以
- 本文实例讲述了Python with关键字,上下文管理器,@contextmanager文件操作。分享给大家供大家参考,具体如下:demo.
- 不废话,直接看代码,需要的根据需求完善。var getKeyCode = function (key) { var key_co
- pytorch中的transforms模块中包含了很多种对图像数据进行变换的函数,这些都是在我们进行图像数据读入步骤中必不可少的,下面我们讲
- 前言根据《2021年Stackoverflow开发者调查》,SQL是最常用的五种编程语言之一。所以,我们应该多投入时间来学习SQL。由Sto
- 很久没有写文章,最近一直在忙于找工作和找房子。哎,现在终于安定下来了,哎,又叹息一下,是因为我把去淘宝面试的机会也推掉了,本来以为要卷铺盖回
- #第一种def delRepeat(liebiao): for x in liebiao: while li
- 我写的这个程序import tensorflow as tfsess=tf.InteractiveSession()x=tf.Variabl
- 1.使用 urllib2 实现#! /usr/bin/env python# -*- coding=utf-8 -*- import url