‘IT DOC’ Posts

 

nginx upstream based on http header

Read full article  | 评论关闭

upstream apache {
     server 127.0.0.1:8080;
}

upstream staging {
     server 127.0.0.1:8081;
}

upstream development {
     server 127.0.0.1:8082;
}

# map to different upstream backends based on header
map $http_x_server_select $pool {
     default "apache";
     staging "staging";
     dev "development";
}

server {
     listen 80;
     server_name example.com;
     location / {
          proxy_pass http://$pool;

          #standard proxy settings
          proxy_set_header X-Real-IP $remote_addr;
          proxy_redirect off;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_redirect off;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_set_header X-NginX-Proxy true;
          proxy_connect_timeout 600;
          proxy_send_timeout 600;
          proxy_read_timeout 600;
          send_timeout 600;
     }
}

Read More

json 中文显示乱码

Read full article  | 评论关闭

方法一

print res_content.decode(‘raw_unicode_escape’)

 

方法二

print json.dumps(json.loads(result),ensure_ascii=False)

Read More

http cache

Read full article  | 评论关闭

 

 

Last-Modified  &  ETag  (判断是否修改)

Cache-Control & Expires  (缓存多久)

Read More

GITLAB /var/opt/gitlab/.ssh/authorized_keys 未更新

Read full article  | 评论关闭

 

用户添加public key 后,/var/opt/gitlab/.ssh/authorized_keys 未更新, 重启sidekiq即可!

$ sudo gitlab-ctl kill sidekiq

$ sudo gitlab-ctl start sidekiq

Read More

GITLAB 修改DNS

Read full article  | 评论关闭

 

修改文件 “/var/opt/gitlab/gitlab-rails/etc/gitlab.yml”

修改成如下的样子就好了哦。

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: gitlab.ops.ac.cn
    port: 80
    https: false
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Read More

mongoengine 更新

Read full article  | 评论关闭

mongoengine 更新

collection.update({‘userid’:int(float(item))},{‘$set’:{‘status’:1}},upsert=False,multi=True)

有兴趣可以研究一下update的四个参数:

第一个为匹配

第二个为条件(条件上可以大作文章),

第三个为没找到是否插入,

第四个为是否支持多操作

Read More

django view太大,切分到不同的目录

Read full article  | 评论关闭

(新增目录下面一定得有__init__.py,    方法1,需要修改__init__.py,  方法2可以将__init__.py 保持为空)

备注:view 子目录引用model, 可用 from app_name.models import * 方式引用, 记得加上 app_name

方法1:

Remove the views.py file and create a directory named views. Add a __init__.py file inside it and create the separated view files.

|∙∙core/
  |∙∙__init__.py
  |∙∙admin.py
  |∙∙migrations/
  |∙∙models.py
  |∙∙tests.py
  |∙∙urls.py
  |∙∙views/
    |∙∙__init__.py
    |∙∙alpha.py
    |∙∙beta.py

views/__init__.py

This is an important step: import all the modules inside each view file.

from .alpha import *
from .beta import *

views/alpha.py

from django.shortcuts import render

def view_a(request):
    return render(request, 'view_a.html')

def view_b(request):
    return render(request, 'view_b.html')

views/beta.py

from django.shortcuts import render

def view_c(request):
    return render(request, 'view_c.html')

def view_d(request):
    return render(request, 'view_d.html')

urls.py

You don’t need to change anything here.

from django.conf.urls import url
import .views

urlpatterns = [
    url(r'^aaa$', views.view_a, name='view_a'),
    url(r'^bbb$', views.view_b, name='view_b'),
    url(r'^ccc$', views.view_c, name='view_c'),
    url(r'^ddd$', views.view_d, name='view_d'),
]

方法2:

Remove the views.py file and create a directory named views. Add a __init__.py file inside it and create the separated view files.

|∙∙core/
  |∙∙__init__.py
  |∙∙admin.py
  |∙∙migrations/
  |∙∙models.py
  |∙∙tests.py
  |∙∙urls.py
  |∙∙views/
    |∙∙__init__.py
    |∙∙alpha.py
    |∙∙beta.py

views/alpha.py

from django.shortcuts import render

def view_a(request):
    return render(request, 'view_a.html')

def view_b(request):
    return render(request, 'view_b.html')

views/beta.py

from django.shortcuts import render

def view_c(request):
    return render(request, 'view_c.html')

def view_d(request):
    return render(request, 'view_d.html')

urls.py

You don’t need to change anything here.

from django.conf.urls import url
import .views

urlpatterns = [
    url(r'^aaa$', views.view_a, name='view_a'),
    url(r'^bbb$', views.view_b, name='view_b'),
    url(r'^ccc$', views.view_c, name='view_c'),
    url(r'^ddd$', views.view_d, name='view_d'),
]



Read More

virtualenv 准备django 环境

Read full article  | 评论关闭

virtualenv ./env_chq -p /opt/apps/python/bin/python

pip install django

django-admin startproject pj_chq .

python manage.py startapp app_chq

Read More

根据列表内字典的某个KEY 进行排序

Read full article  | 评论关闭

方法1 (lambda):

newlist = sorted(list_to_be_sorted, key=lambda k: k['name']) 
备注:  如果key类型为不同类型,注意一下转换,比如int  (k: int(k['name']))

方法2:

from operator import itemgetter

newlist = sorted(list_to_be_sorted, key=itemgetter('name')) 

newlist = sorted(list_to_be_sorted, key=itemgetter('name'), reverse=True)

Read More

python mongo Q

Read full article  | 评论关闭

 

from mongoengine.queryset.visitor import Q as mongo_Q

from django.db.models import Q as normal_Q

Read More