Python,HTML,CSSの連携

下記コーディングはQiitaの記事を参考にさせていただきました。
-Python(app.py)

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# app.py

from flask import Flask, redirect ,request,render_template

app = Flask(__name__)

@app.route("/check")
def check():
    return render_template('check.html')

@app.route('/',methods=['POST'])
def index():
    my_age = int(request.form["age"])
    my_name = request.form["name"]
    return render_template('index.html',age=my_age,name=my_name)

if __name__ == '__main__':
    app.run(debug=True)

-HTML(check.html)

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>年齢確認</title>
<!--    <link rel="stylesheet" type="text/css" href="{{url_for('static', filename='style.css')}}" />  -->
    <link rel="stylesheet" type="text/css" href="static/css/style.css" />
</head>
<body>

    <form action="/" method="post">
        <h1>年齢確認</h1>
        <input type="text" name="name" placeholder="名前" required/>
        <input type="number" name="age" placeholder="年齢" required/>
        <button>年齢確認</button>
    </form>

</body>
</html>

-HTML(index.html)

<!DOCTYPE html>  <!-- index.html -->
<html lang="ja">
    <head>
        <meta charset="UTF-8">
        <title>18禁のサイト</title>
<!--        <link rel="stylesheet" type="text/css" href="style.css" />  -->
	<link rel="stylesheet" type="text/css" href="static/css/style-04.css" />
        <!--[if lt IE 9]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
    </head>
    <body>
    <h1>射幸心を煽りまくるホームページ</h1>
    {% if age >= 18 %}
    {{name}}さんは18歳以上ですね。
    {% else %}
    {{name}}さんみたいな方はこんなHP見ちゃいけません?
    {% endif %}

    </body>
</html>

-CSS(style.css)

@charset 'utf-8';
body	 {
	background: sandybrown;
	color: darkgreen;
	margin-left: 2m;
	margin-right: 2m;
}

-CSS(style-04.css)

@charset 'utf-8';
body	 {
	background: violet;
	color: darkgreen;
	margin-left: 2m;
	margin-right: 2m;
}

以上

↑人気ブログランキングに参加しています。ポチっと1票を!

四則演算(PyCharm)

四則演算

-PyCharmとChromeで実施

#!/usr/bin/python3
# -*- coding: utf-8 -*-
#demo09.py

from flask import Flask,request

app = Flask(__name__)

@app.route('/')
def index():
    a = int(request.args.get("a"))
    b = int(request.args.get("b"))
    op = request.args.get("op")
    
    if op == "a":
          c = str(a + b)
          return "demo09 Add answer = "+c
    elif op == "s":
          c = str(a - b)
          return "demo09 Subtract answer = "+c
    elif op == "m":
          c = str(a * b)
          return "demo09 Multiply answer = "+c
    elif op == "d":
          c = str(a // b)
          return "demo09 Divide answer = "+c
    elif op == "r":
          c = str(a % b)
          return "demo09 Reminder answer = "+c
    elif op == "p":
          c = str(a ** b)
          return "demo09 Power answer = "+c
    else:
          return "demo09 Illeagal operator"

if __name__ == '__main__':
    app.run(debug=True)
#http://127.0.0.1:5000/?op=p&a=3&b=2

以上

↑人気ブログランキングに参加しています。ポチっと1票を!