CentOS 6.8 部署django项目一

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/',
}

这样就可以在页面配置模板参数。

最新文章

  1. Windows服务已经标记为删除
  2. 面向对象Part1对象的创建和Static!
  3. java io 流分类表
  4. 分享我用Qt开发的应用程序【二】在Qt应用程序中使用字体图标fontawesome
  5. Innodb物理存储结构系列2 行记录格式
  6. IOS 7 Study - UISegmentedControl
  7. 企业级搜索引擎Solr 第三章 索引数据(Indexing Data)[3]
  8. http 需要掌握的知识点(一)
  9. WCF学习系列一_创建第一个WCF服务
  10. [Android]The connection to adb is down, and a severe error has occured.
  11. 51nod 1244 莫比乌斯函数之和(杜教筛)
  12. 理解用requireJs 来实现javascript的模块化加载
  13. php引入文件(include 和require的区别)
  14. Spring Security 入门(3-10)Spring Security 的四种使用方式
  15. Access denied for user 'root'@'localhost' (using password:YES) Mysql5.7
  16. jetty服务器原理与maven集成
  17. 5)django-模板
  18. 第一个python程序--hello,world
  19. IE 主页被恶意篡改的解决方法
  20. Spring_Task初探(注解,XML配置)

热门文章

  1. Java生成多数值二元运算结果集
  2. Android 视频 教程 源码 电子书 网址
  3. sklearn 的train_test_split
  4. 【CH1602】最大异或和 trie+贪心
  5. Machine Learning Netsite
  6. JS基本包装类型之三(String)
  7. 修改sqlarchemy源码使其支持jdbc连接mysql
  8. ​python高级数据可视化视频Dash1
  9. 采集化工内容写入TXT文本
  10. OS + Linux RedHat 6 / redhat 6 configuration / configure / autoconf / make / make install