Coder Social home page Coder Social logo

flask_app_template's Introduction

flask_app_template

poetry + flask + semantic-uiのボイラープレートです。

ディレクトリ構成はざっくりこんな感じ。

.
├── src
│   └── flask_app_template
├── static
│   └── app.js
├── templates
│   ├── b_header.html
│   ├── hello.html
│   ├── index.html
│   └── layout.html
├── tests
│   ├── __pycache__
│   ├── __init__.py
│   └── test_flask_app_template.py
├── .gitignore
├── LICENSE
├── README.md
├── app.py
├── poetry.lock
├── pyproject.toml
└── pytest.ini

通常のpoetryと違うのは以下のディレクトリ。

  • template(flaskのtemplateディレクトリ)
  • static(jsやcss、画像等を置く場所)

加えてルートディレクトリにapp.pyを置いています。

起動方法

poetry install # 初回のみ
poetry shell
python app.py

使い方

ブラウザ表示部分

templateディレクトリ

  • layout.html
    • 全ページ共通のhtml(headやヘッダー等)
  • b_header.html
    • layoutからヘッダー(headタグではなくパーツ部分)を抜き出したもの
  • index.html
  • hello.html
    • ページ固有のhtml

staticディレクトリ

  • app.js
    • ブラウザで読み込むjs
  • style.css
    • ブラウザで読み込むcss

データ作成部分

  • app.py
    • 主にルーティングを行う
    • 簡単な値を渡す
    • 複雑なデータはsrcディレクトリで作りimportする
from flask import Flask
from flask import render_template
from src.flask_app_template import settings, df

app = Flask(__name__)


@app.route("/")
def home():
    return render_template("index.html", **settings)


@app.route("/hello")
def hello():
    settings["name"] = "jiro"
    settings["table1"] = df.to_html(classes="ui striped table", index=False)
    return render_template("hello.html", **settings)


if __name__ == "__main__":
    app.run(port=5001, debug=True)
  • srcディレクトリ
    • app.pyを見通しよく保つ為にsrcディレクトリで値や関数を作成する
    • サイトのtitleはsettings.site_titleとして設定する

参考サイト

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.