python -c 'import django;print(django.get_version())'
django安装
python
python get-pp.py
pip install django
pip install MySQL-python
sudo apt-get install python-dev
sudo apt-get install libmysqlclient-dev
yum install python-sqlite
pip install django-celery
pip3 install django==1.9
pip install redis
sudo apt-get install redis-tools
pip install django-grappelli
安装静态bootstrap
pip install django-bootstrap-static==3.3.6
windows接口
pip install pypiwin32
ubuntu 上worker启动
会崩溃,需要替换 librabbitmq
jay@jay-linux:~$ sudo apt-get remove python-librabbitmq #删除原来的包
jay@jay-linux:~$ sudo pip install librabbitmq
Model
1.query object from model object = GlobalConfig.objects.get(skey=“key")
- query object list model : list = Global.objects.all()
django 创建:
python manage.py makemigrations app
python manage.py migrate
python manage.py createsuperuser --username=admin
sender.request_class._get_request()
from
django
.core
.signals
import
request_finished
request_finished
.connect
(
my_callback
)
注意alias和root的区别。
django中:
response['X-Accel-Redirect']='/protected_files/%s'%filename
这样当向django view函数发起request时,django负责对用户权限进行判断或者做些其它事情,然后向nginx转发url为 /protected_files/filename的请求,nginx服务器负责文件/var/www/protected_files /filename的下载:
@login_required
def document_view(request, document_id):
book = Book.objects.get(id=document_id)
response = HttpResponse()
name=book.myBook.name.split('/')[-1]
response['Content_Type']='application/octet-stream'
response["Content-Disposition"] = "attachment; filename={0}".format(
name.encode('utf-8'))
response['Content-Length'] = os.path.getsize(book.myBook.path)
response['X-Accel-Redirect'] = "/protected/{0}".format(book.myBook.name)
def document_view(request, document_id):
book = Book.objects.get(id=document_id)
response = HttpResponse()
name=book.myBook.name.split('/')[-1]
response['Content_Type']='application/octet-stream'
response["Content-Disposition"] = "attachment; filename={0}".format(
name.encode('utf-8'))
response['Content-Length'] = os.path.getsize(book.myBook.path)
response['X-Accel-Redirect'] = "/protected/{0}".format(book.myBook.name)
return response
files = os.listdir(os.path.join(unpackPath,
'META-INF/'))
for f in files:
if f.endswith( '.RSA') or f.endswith( '.DSA') :
for f in files:
if f.endswith( '.RSA') or f.endswith( '.DSA') :
signaturesMD5 = getSignMD5(os.path.join(unpackPath, 'META-INF/',f))
python manage.py celery worker --loglevel=info --beat |
python manage.py celery worker --loglevel=info
python manage.py celery beat
export C_FORCE_ROOT="true"
rabbitmqctl add_vhosts appdict
rabbitmqctl list_vhosts
rabbitmqctl set_permissions -p /appdict appdict ".*" ".*" ".*"