[Django] 常用基本指令
- 新建專案
django-admin startproject mysite
- 新建app
python manage.py startapp myapp
- 啟動sever
python manage.py runserver localhost:443
- 建立super user
python manage.py createsuperuser
django-admin startproject mysite
python manage.py startapp myapp
python manage.py runserver localhost:443
python manage.py createsuperuser
# setup django environment using existing settings file
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")
django.setup()
# start of main code
from myapp.models import *
testobjs = mymodel.objects.all()
print(testobjs)
pip install --upgrade pip
LOAD DATA INFILE "C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Uploads\\plane-data.csv" INTO TABLE plane
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(tailnum,type,manufacturer,@issue_date,model,status,aircraft_type,engine_type,year)
SET issue_date=str_to_date(@issue_date, "%m/%d/%Y");
解法: 到my.ini,將此設定修改成空字串
secure-file-priv=""
解法: 到my.ini,將此設定修改成空字串
sql-mode=""
解法: 使用excel,另存成.csv檔案,即可自動使用,,分隔。
#include <ctime>
using namespace std;
clock_t begin = clock();
target_func();
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
cout << "Elapsed time: " << elapsed_secs << " sec." << endl;
將欲取消追蹤的檔案加入.gitignore
在repo中刪除該檔案:
git rm -r --cached .
git commit -m "Untrack and delete filename in repo."
push到遠端
python -m venv mytargetdir
source activate myenv
source deactivate
pip freeze > requirements.txt
pip install -r requirements.txt
#新建virtual env:
conda create -n yourenvname python=x.x
#使用環境檔案建立虛擬環境
conda env create -f environment.yml
#查看所有env:
conda info -e
#啟用虛擬環境
conda activate yourenvname
#關閉虛擬環境
conda deactivate
#刪除虛擬環境:
conda env remove -n yourenvname
#匯出虛擬環境:
conda env export > environment.yml
#使用環境檔案安裝套件
conda env update -n yourenvname --file environment.yml
Step 1: From your project repository, bring in the changes and test.
git fetch origin
git checkout -b steven origin/steven
git merge master
Step 2: Merge the changes and update on GitHub.
git checkout master
git merge --no-ff steven
git push origin master
Conflict with binary files:
git checkout --theirs -- path/to/conflicted-file.txt
git checkout --ours -- path/to/conflicted-file.txt
由新到舊 D -> C -> B -> A
要把D和C合併成單一個C’
rebase -i <B的SHA-1>
若要rebase初始commit(A):
rebase -i --root
pick <C的SHA-1> C的commit訊息
squash <D的SHA-1> D的commit訊息
編輯C’的commit訊息
P.S.若要push到github上則要強迫push:
git push --force
git config --global user.email "my_email"
git config --global user.name "my_name"
git init
git status
git add .
git add -A
git commit -m “commit message”
# 顯示資訊
git remote -v
git remote show origin
# 刪除目前origin
git remote rm origin
# 新增origin
git remote add origin git@github.com:SongRongLee/xxxxx.git
git push -u origin master
or
git branch -u origin/master
#以後只需要:
git push
git reset --hard HEAD^
git reset --hard HEAD~2
# 以遠端分支為藍本建立本地new-branch
git checkout -b new-branch origin/master
# Delete a remote branch
git push -d origin bad-branch
# Delete a local branch
git branch -d bad-branch
# Sync remote branch information after deletion
git fetch --prune
# List all remote and local branches
git branch -a
# 修改branch名稱
git branch -m my-new-name
# push本地的local-branch到origin/remote-branch
git push origin local-branch:remote-branch
# Shows changes from from_branch to to_branch
git diff from_branch to_branch
# pull但是保留local change
git stash
git pull
git stash pop
# Stash untracked files
git stash -u
# List all stashes
git stash list
# Pop a certain stash
git stash pop stash@{n}
# Stash with a given message
git stash -m my_message
git update-ref -d HEAD
git reset
git checkout -- filename
git reset --hard origin/master
git reset HEAD@{1}
git mv
git status --ignored
git clean -dn # Dry run
git clean -df # Actual remove
git reflog