CentOS 6.8 部署django项目二
2024-10-10 20:19:57
1、项目部署后发现部分页面的样式丢失,是因为在nginx中配置的static路径中未包含。
解决:在settinfs.py中添加:
STATIC_ROOT = os.path.join(BASE_DIR, "static_all")
然后执行:
python3 ./manage.py collectstatic
项目下自动生成static_all文件夹,里面包含所有的静态文件,然后修改nginx的配置文件,指向该文件路径。
2、自定义模板参数
如果希望向页面传递参数,类似于{{MEDIA_URL}}这种,我们可以模仿django添加自己的处理方法:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
# 'django.template.context_processors.media', # 配置html页面获取MEDIA_URL路径
'configs.sysconf.media'
],
},
},
]
注释掉django的django.template.context_processors.media,添加自己的configs.sysconf.media,内容是:
from configs.models import ServerConfig def media(request):
"""
Adds media-related context variables to the context.
"""
try:
serverConfig = ServerConfig.objects.all()[0]
image_server = serverConfig.img_server_ip + ':' + serverConfig.img_server_port.__str__()
except Exception:
image_server = '127.0.0.1' return {'MEDIA_URL': 'http://' + image_server + '/images/',
'VOD_URL': image_server + '/vods/',
'ANNEX_URL': image_server + '/annexs/',
}
这样就可以在页面配置模板参数。
最新文章
- Windows服务已经标记为删除
- 面向对象Part1对象的创建和Static!
- java io 流分类表
- 分享我用Qt开发的应用程序【二】在Qt应用程序中使用字体图标fontawesome
- Innodb物理存储结构系列2 行记录格式
- IOS 7 Study - UISegmentedControl
- 企业级搜索引擎Solr 第三章 索引数据(Indexing Data)[3]
- http 需要掌握的知识点(一)
- WCF学习系列一_创建第一个WCF服务
- [Android]The connection to adb is down, and a severe error has occured.
- 51nod 1244 莫比乌斯函数之和(杜教筛)
- 理解用requireJs 来实现javascript的模块化加载
- php引入文件(include 和require的区别)
- Spring Security 入门(3-10)Spring Security 的四种使用方式
- Access denied for user 'root'@'localhost' (using password:YES) Mysql5.7
- jetty服务器原理与maven集成
- 5)django-模板
- 第一个python程序--hello,world
- IE 主页被恶意篡改的解决方法
- Spring_Task初探(注解,XML配置)
热门文章
- Java生成多数值二元运算结果集
- Android 视频 教程 源码 电子书 网址
- sklearn 的train_test_split
- 【CH1602】最大异或和 trie+贪心
- Machine Learning Netsite
- JS基本包装类型之三(String)
- 修改sqlarchemy源码使其支持jdbc连接mysql
- ​python高级数据可视化视频Dash1
- 采集化工内容写入TXT文本
- OS + Linux RedHat 6 / redhat 6 configuration / configure / autoconf / make / make install