python+django web开发续

配置django-cachalot

目的:用来缓存query
用法:安装pip, sudo apt-get install python-pip
   安装cachalot, sudo pip install django-cachalot
   配置cachalot, 在settings.py里面INSTALLED_APPS = (..., 'cachalot', ...)
原理:就是给django的sql方法打patch,没执行过就执行,然后缓存,更新后删除缓存

配置nginx + uwsgi + django

目的:django本身是一个web框架,可以提供web服务,但是要应对线上的高并发就力不从心了。将django部署到nginx上用来提供服务需要uwsgi,安装:
apt-get install uwsgi uwsgi-core uwsgi-plugin-python
之后在django项目下面配置两个文件:
uwsgi.xml

  127.0.0.1:8077
  20
  python
  true
  /usr/share/nginx/uwsgi.pid
  4
  django_wsgi  #配置文件
  /home/ubuntu/featureview_server/Django-1.7.1/work/doodle_featureview   #项目的路径
  true
  true
  true
  true
  6048

django_wsgi.py
#!/usr/bin/env python
# coding: utf-8

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "doodle_featureview.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

配置nginx

打开nginx.conf或者site-enabled/default配置uwsgi + django
location /admin {
		uwsgi_pass 127.0.0.1:8077;
		include uwsgi_params;
	}
	location /featureview {
		uwsgi_pass 127.0.0.1:8077;
		include uwsgi_params;
	}



你可能感兴趣的:(django,缓存,移动开发)