【Django】ForeignKeyについてのメモ
1対多で使う。
以下のサイトがわかりやすい https://noumenon-th.net/programming/2019/12/02/foreignkey/
【Python】arg, kwargsについて
arg
arg:タプル形式で引数が与えられる
In [1]: def arg_sample(*args): ...: print(args) ...: print(type(args)) ...: In [2]: arg_sample(1,4,2,3) (1, 4, 2, 3) <class 'tuple'>
kwargs
dict形式で引数を受け取る
In [14]: def kwargs_sample(**kwargs): ...: print(kwargs) ...: print(type(kwargs)) ...: In [17]: kwargs_sam(k1=1, k2=2) {'k1': 1, 'k2': 2} <class 'dict'> In [18]: history -p >>> def arg_sample(*args): ... print(args) ... print(type(args))
fetchでBeaer認証
let token = "<<your token>>" var myHeaders = new Headers(); myHeaders.set('Content-Type', 'application/json'); myHeaders.set('Authorization', "Bearer " + token); var info = { method: 'GET', headers: myHeaders, mode: 'cors', credentials: 'include' , cache: 'default' }; var responce = await(await fetch('url' ,info, ).then(this.handler) .catch(this.error) ).json(); }
reactのメモ
reactメモ
props
propsはコンポーネントを初期化する時に設定できる値。 後からは変更できない
this.state.logged_in
ログインしているかを判定する
jwt認証の時にはfetchにaccess tokenを加える
fetch('http://127.0.0.1:8000/api/insert_memo/', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `JWT ${localStorage.getItem('token')}` }, body: JSON.stringify({ name: 'Hubot', login: 'hubot', }) }).then(function(response) { // レスポンス結果 console.log(response); window.alert('Response: ' + response); }, function(error) { // エラー内容 window.alert('Error: ' + error); });
render()
以下には1つのブロックしか入らない
render(){
return
}
Componentと
https://ja.reactjs.org/docs/react-component.html
state
Componentの状態を表す
fetch
fetchはGET、POST処理などを担う
=> アロー関数
これはReact特有というものではない
let func = (x) => { console.log(x); }
xが引数
curlのサンプル
curl -d "param1=value1¶m2=value2" -X POST http://127.0.0.1:5000/insert