やったこと
前回(bottleでPandasのDataFrameをCSV形式でダウンロードする。)からの続き。
1.Pythonのフレームワーク「bottle」にbootstrap4.1を導入した。
bootstrapの公式サイトのコチラのページにあるコードをテンプレートのHTMLファイルに追記した。
<!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Optional JavaScript --> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
bootstrapを導入した後、ボタンの色を変え、「必須」を赤色で表示させた。
2.地味にフォームの入力項目を必須にした。
(参考ページ)
HTML5タグリファレンス
作成コード
<!DOCTYPE html> <html lang="ja"> <head> <!-- Required meta tags --> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> <title> {{ title }} </title> </head> <body> {% block contents %} {% endblock %} <!-- Optional JavaScript --> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script> </body> </html>
{% extends 'base.html' %} {# base.html の contents の中に入れるコンテンツ #} {% block contents %} <div class="container"> <h1>Togglのデータをエクスポートするツールです。</h1> <form action = "/download" method = "post"> メールアドレス<span class = "badge badge-danger">必須</span> : <input name = "email" type = "email" placeholder = "example@gmail.com" required/><br> パスワード<span class = "badge badge-danger">必須</span> : <input name = "password" type = "password" placeholder="xxxxxxxx" required/><br> 日付<span class = "badge badge-danger">必須</span> :<input name = "date" type = "date" required/><br> <button type = "submit" class = "btn btn-primary">ダウンロード</button> </form> </div> {% endblock %}
実行結果
つまづいたところ
特になし。
やってみた感想
CSSを自分で書かずに簡単にデザインを変更できるのには感動した。どんどんコーディングがやりやすくなっているんだろうなぁ。
ただ、少し勉強しないといけないところがある。
参考記事
・Bootstrap4の使い方特設サイトを公開しました
・エンジニアはもう一度CSSとちゃんと向き合ってみよう – 詳細度編
コメント