django 实现简单的插入视频
作者:羽二 时间:2023-12-24 09:59:33
直接将 视频的HTML网址存入models ,以字符串的形式
#关于我们 CharField
class About(models.Model):
title = models.CharField(u'视频html网址',max_length=256)
content = models.TextField(u'内容')
phone = models.IntegerField(u'电话')
address = models.CharField(u'地址',max_length=256)
def __unicode__(self):
return self.title
然后传入到前端
def about(request):
about = About.objects.all()
return render(request,'about.html',{'about':about})
{% for abouts in about %}
<div class="videopage">
<div>
{{abouts.title|safe }}
</div>
</div>
<div class="post">
<h1>关于我们</h1>
{{ abouts.content }}
<h1>联系方式:</h1><body>{{abouts.phone }}</body>
</div>
{% endfor %}
{% endblock %}
然后直接把字符过滤成html代码 视频就出来了
补充知识:django上传媒体文件至media的配置部署
在Django应用的文件夹下,经常会发现这两个文件夹:static, media; static称为静态文件夹,用于存放CSS, JavaScript, 网站logo等不变的文件;相对的,把media称为媒体文件夹,用于存放用户上传的图片。
第一步,在settings.py中配置media文件
# 配置头像上传路径
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
第二步在项目文件的urls.py中配置media路由
from django.conf.urls import url
from django.views.static import serve
from . import settings
urlpatterns = [
# ... the rest of your URLconf goes here ...
url(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT})
]
在app的models.py中定义上传图片
class User(models.Model):
username = models.CharField(max_length=32, unique=True)
password = models.CharField(max_length=256)
email = models.CharField(max_length=64, unique=True)
sex = models.BooleanField(default=False)
icon = models.ImageField(upload_to='icons') # 头像上传到media/icons目录中
is_delete = models.BooleanField(default=False)
class Meta:
db_table = 'user'
来源:https://blog.csdn.net/qq_34963461/article/details/52205618
标签:django,插入,视频
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何用idea数据库编写快递e站
2024-01-23 08:43:56
![](https://img.aspxhome.com/file/2023/7/89597_0s.png)
Pytorch 多块GPU的使用详解
2021-01-21 09:19:09
![](https://img.aspxhome.com/file/2023/0/135240_0s.jpg)
JavaScript变量声明的var、let、const详解
2024-05-09 15:07:06
没有SQL Server数据库时如何打开.MDF文件
2024-01-15 05:58:52
![](https://img.aspxhome.com/file/2023/0/106210_0s.jpg)
Python3爬虫带上cookie的实例代码
2021-11-10 18:06:58
怎么样在网页上读取远程xml的数据
2008-10-10 17:43:00
python访问mysql数据库的实现方法(2则示例)
2024-01-23 05:58:41
详解Python爬虫的基本写法
2022-12-26 07:49:45
基于python实现名片管理系统
2023-02-03 12:33:50
![](https://img.aspxhome.com/file/2023/2/104792_0s.jpg)
在Python上基于Markov链生成伪随机文本的教程
2023-07-02 09:24:03
简单触发器的使用 献给SQL初学者
2024-01-17 18:27:18
![](https://img.aspxhome.com/file/2023/4/113574_0s.jpg)
基于Python编写一个刷题练习系统
2022-10-01 13:28:34
![](https://img.aspxhome.com/file/2023/2/79442_0s.png)
python打印n位数“水仙花数”(实例代码)
2021-06-11 20:35:36
python统计一个文本中重复行数的方法
2021-08-20 12:50:46
Python输出各行命令详解
2021-12-03 05:29:18
![](https://img.aspxhome.com/file/2023/3/100923_0s.jpg)
Linux CentOS下docker部署Asp.Net Core(.Net6)
2024-06-05 15:44:00
![](https://img.aspxhome.com/file/2023/4/122834_0s.jpg)
python调用subprocess模块实现命令行操作控制SVN的方法
2022-07-18 02:01:03
几款Python编译器比较与推荐(小结)
2022-07-21 01:31:56
![](https://img.aspxhome.com/file/2023/1/85121_0s.png)
javascript函数定义的几种区别小结
2024-04-10 10:40:03
python3 requests库文件上传与下载实现详解
2021-10-10 15:31:07