一、Git使用
1 ## GIT常用执令说明 2 3 * 初始化git项目 4 > git init 5 6 * 查看当前目录状态 7 > git status 8 9 * 把代码提交到stage区 10 > git add file.txt 11 12 > git add . 13 14 * 从stage区提交代码到仓库 15 > git commit -m "说明" 16 17 * 查看commit日志 18 > git log 19 20 > git log --pretty=oneline 21 22 * 查看提交,回滚所有操作 23 > git reflog 24 25 26 * 回滚到上一个版本 27 > git reset --hard HEAD^ 28 29 30 * 回滚到上二个版本 31 > git reset --hard HEAD^^ 32 33 * 回滚到指定版本 34 > git reset --hard afa3kf 35 36 * 删除文件 37 > git rm file.txt 38 39 > git commit -m "del file.txt" 40 41 * 从stage区删除 42 > git add test.txt 43 44 > git reset test.txt 45 46 * 文件放弃修改 47 > git checkout -- file.txt 48 49 50 * 增加远程GIT 51 > git remote add origin https://github.com/willianflasky/s16day21.git 52 53 54 #### 关联GITHUB 55 ==本地无项目文件== 56 ``` 57 echo "# mysite" >> README.md 58 git init 59 git add README.md 60 git commit -m "first commit" 61 git remote add origin git@github.com:willianflasky/mysite.git 62 git push -u origin master 63 64 ``` 65 ==本地有项目文件== 66 ``` 67 68 git remote add origin git@github.com:willianflasky/mysite.git 69 git push -u origin master 70 71 ``` 72 73 #### 备注 74 75 1.两种方式:https and git 76 2.本地生成公钥添加到GITHUB 77 78 79 * .gitignore 80 > https://github.com/github/gitignore 81 82 * 保存工作区临时地方 83 > git stash 84 85 > git stash list 86 87 > git stash apply 88 89 > git stash drop 90 91 > git stash pop 92 93 94 95 * 分支 96 ``` 97 git branch dev #创建分支 98 git checkout dev #切换到dev分支 99 100 git checkout -b dev #切换到dev分支,如果没有这个分支则创建 101 102 git pull origin master #换取远程master主干代码 103 104 git merge dev #将当前分支合并dev分支 105 106 ``` 107 108 #### ==合并分支套路== 109 ``` 110 1.git checkout master #切换到master 111 2.git pull #拉取远程最新master代码 112 3.git merge dev #在master分支上合并dev分支 113 4.push push origin master #把合并后的代码push到远程master 114 ```
二、Celery和Django结合
1.项目结构
1 - proj/ 2 - proj/__init__.py 3 - proj/settings.py 4 - proj/urls.py 5 - manage.py
2.proj/proj/celery.py
1 from __future__ import absolute_import, unicode_literals 2 import os 3 from celery import Celery 4 5 # set the default Django settings module for the 'celery' program. 6 os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings') 7 8 app = Celery('proj') 9 10 # Using a string here means the worker don't have to serialize 11 # the configuration object to child processes. 12 # - namespace='CELERY' means all celery-related configuration keys 13 # should have a `CELERY_` prefix. 14 app.config_from_object('django.conf:settings', namespace='CELERY') 15 16 # Load task modules from all registered Django app configs. 17 app.autodiscover_tasks() 18 19 20 @app.task(bind=True) 21 def debug_task(self): 22 print('Request: {0!r}'.format(self.request))
3.proj/proj/__init__.py
1 from __future__ import absolute_import, unicode_literals 2 3 # This will make sure the app is always imported when 4 # Django starts so that shared_task will use this app. 5 from .celery import app as celery_app 6 7 __all__ = ['celery_app']
4.proj/app1/tasks.py
必须放这目录下,而且名字叫tasks
1 - app1/ 2 - tasks.py 3 - models.py 4 - app2/ 5 - tasks.py 6 - models.py
5.proj/app1/tasks.py
1 # Create your tasks here 2 from __future__ import absolute_import, unicode_literals 3 from celery import shared_task 4 5 6 @shared_task 7 def add(x, y): 8 return x + y 9 10 11 @shared_task 12 def mul(x, y): 13 return x * y 14 15 16 @shared_task 17 def xsum(numbers): 18 return sum(numbers)
6.proj/app1/views.py
1 from django.shortcuts import render,HttpResponse 2 3 # Create your views here. 4 5 from bernard import tasks 6 7 def task_test(request): 8 9 res = tasks.add.delay(228,24) 10 print("start running task") 11 print("async task res",res.get() ) 12 13 return HttpResponse('res %s'%res.get())
备注: http://www.cnblogs.com/alex3714/p/6351797.html