Entries from 2021-01-01 to 1 year

Firestoreについて

データモデル 大きく3つの要素を指定することになります。 データ フィールドと値のペアを複数持っている(オブジェクト) ドキュメント 1つのデータを持っている ドキュメントのIDを指定する必要がある コレクション 複数のドキュメントを持っている コレ…

Providerとは

Providerとは Flutter開発において、初心者→中級者にステップアップする上で、Providerを使うというのは避けては通れない。Google社は、BloC Patternを使うことが2018年ぐらいに推奨していましたが、その後、アプリの規模に対して学習コストが高かったり、こ…

Flutter基本構造(書き方)

今回はアプリの基本構造(書き方)について紹介します。 以下のコードを解説したいと思います。 import 'package:flutter/material.dart' void main() { runApp(MyApp());} //起動時にmain関数呼び出し //main関数からrunApp関数を呼び出すことで、MyAppが実行…

【ytmusic】基本操作

import requestsfrom ytmusicapi import YTMusicimport json ytmusic = YTMusic("headers_auth.json") #プレイリスト作成→曲検索→検索結果をプレイリストに登録playlistId = ytmusic.create_playlist('test', 'test description')search_results = ytmusic.s…

【ytmusic】プレイリスト作成→曲検索→検索結果をプレイリストに登録

import requestsfrom ytmusicapi import YTMusicimport json ytmusic = YTMusic("headers_auth.json") #プレイリスト作成→曲検索→検索結果をプレイリストに登録playlistId = ytmusic.create_playlist('test', 'test description')search_results = ytmusic.s…

current user Section 11, Lecture 52

ログインしてるのにログイン画面に飛べるのを処理する。 以下のコードを設定するだけ良い。 if current_user.is_authenticated:はもしすでにログイン済みの場合はフラッシュメッセージを表示する。 @at.route('/login', methods=['GET', 'POST']) def do_the…

logging users out Section 11, Lecture 51

layout.htmlに以下を追加で記述して、各ファンクションとリンクさせる。 <li><a href="{{ url_for('main.display_books') }}"> Home </a></li> <li><a href="{{ url_for('authentication.register_user') }}"> Register </a></li> <li> {% if current_user.is_authenticated %} <a href="{{ url_for('authentication.log_out_user') }}"> SignOut </a> {…</li>

display login status Section 11, Lecture 50

ログイン状態か表示する方法 app/catalog/templates/layout.htmlに以下を追記する。 <a href=""> {% if current_user.is_authenticated %} Logged-In as <b style="color: deeppink"> {{ current_user.user_name.title() }} </b> {% else %} Not Logged-In {% endif %} </a> 実際にやってみる ログイン状態…

よくわkラン letting users login Section 11, Lecture 49

ログイン機能を改善する。 models.pyに以下を追記する ユーザーが入力したpasswordを渡すことでdbにあるハッシュと一致するかをチェックする。 def check_password(self, password): return bcrypt.check_password_hash(self.user_password, password) もし…

Flask-loginの説明 login manager and usermixin classes Section 11, Lecture 48

Flask Loginに関して models.pyに以下を記述することで login managerのloaderが使える。 int(id)にする必要がある。 今回はこの4つについて学ぶ 1. LoginManager 2. @login_manager.user_loader 3. load_user()custom method 4. UserMixin() auth/forms.py…

重複確認 writing custom validations Section 11, Lecture 47

すでにデータが存在しているかを確認する方法 forms.pyで文字数や有効性を確認をしていた。 forms.pyに関数を作る→forms.pyのチェック機能に重複確認関数を追加する必要がある。 def email_exists(form, field): email = User.query.filter_by(user_email=fi…

ユーザー登録のコード作成2 capturing user credentials using forms part 2 Section 11, Lecture 46

login.htmlを作る。 falseの場合はregistration.htmlに飛ばしてあげる。その場合はformも渡す。 flashメッセージ get_flash_messageに全てのメッセージが登録されている。 layout.htmlにflashを追加することで全てのページでflashメッセージを容易に表示させ…

ユーザー登録のコード作成1 capturing user credentials using forms part 1 Section 11, Lecture 45

route.pyのまとめ 次の順で処理される。 1. localhost/registerにアクセスする。 2. return render_template('registration.html', form=form)でページを表示させる。 3. HTMLからPOSTでname,emai,passwordが飛んでくる。 4. if form.validate_on_submit():…

フォームの作り方 adding data validation to the registration process Section 11, Lecture 44

validatorsを使う事でルール通りしか受け付けないようにする。 まとめ この4つの順に作ればフォームはできる。 1.フォームを作る 2.routeで登録する 3.dbのテーブルを定義する 4.htmlを作成する

basic user registration form and CSRF Section 11, Lecture 41

デフォルトではgetリクエストになる。 none設定をする 1. localhost/registerにアクセスする 2. GETリクエストなのでreturnでページを表示する 3. 次にuserがフォームを入力してsubmitを推した場合はPOSTなので ifぶんのPOSTを発動する。 4. returnにデータ…

creating users in the database Section 11, Lecture 43

models.pyを作る ユーザー管理用のデータベースを作る。 インスタンスではなくクラスを作る。 functionとして@classmethodを作る。 selfではなく、クラスなのでclsを置く。また、パスワードはハッシュ化する。 python3なのでutf-8の設定もする。 【通常の場…

bcryptの使い方の説明 flask login and password hashing using bcrypt Section 11, Lecture 42

bcryptの使い方の説明 最初にやる事は同じ 実際にpasswordをハッシュ化ってどんな風にやっているのか? Bcryptの'generate_password_hash'に注目する!これでハッシュ化する。 $ pip install flask_login $ pip install flask_bcrypt >>> from flask_bcrypt …

a simple form Section 11, Lecture 40

Catalog Packageと同じ流れやる 1. init.py, blueprint 2. app/init.pyに登録する 3. form.pyを作成する 4. route.pyを作成する(functionなど定義する) 5. htmlを準備する Authフォルダーにinit.pyを作る BluePrint をimportする。 blueprintのインスタンス…

Scaling Applications 最低限で動かす

最低限でblueprintを使いこなす。 上から順に書きなぐる Flaskは主にこの3つで構成される。 appフォルダー configフォルダー run.py ├── app │ ├── __init__.py │ ├── __pycache__ │ │ └── __init__.cpython-36.pyc │ ├── auth │ │ ├── __init__.py │ │ └──…