├── .DS_Store ├── Dockerfile ├── main.py ├── requirements.txt ├── static └── style.css └── templates ├── cek_usia.html └── index.html /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deaafrizal/python_flask_1/68104bcd692438790f4b68d4bad7f7ea1b271429/.DS_Store -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.10-slim 2 | 3 | WORKDIR /usr/src/app 4 | 5 | COPY requirements.txt . 6 | RUN pip install -r requirements.txt 7 | 8 | COPY . . 9 | 10 | CMD ["python", "main.py"] 11 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template, request 2 | from datetime import datetime 3 | 4 | app = Flask(__name__) 5 | 6 | @app.route('/') 7 | def main(): 8 | return render_template('index.html') 9 | 10 | @app.route('/usia', methods=['GET', 'POST']) 11 | def cek_usia(): 12 | if request.method == 'POST': 13 | # Ambil data dari form 14 | tahun_lahir = int(request.form['tahun_lahir']) 15 | tahun_sekarang = datetime.now().year 16 | usia = tahun_sekarang - tahun_lahir 17 | return render_template('cek_usia.html', usia=usia, tahun_lahir=tahun_lahir) 18 | return render_template('cek_usia.html', usia= None) 19 | 20 | if __name__ == "__main__": 21 | app.run(host='0.0.0.0') 22 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | flask==2.3.2 2 | -------------------------------------------------------------------------------- /static/style.css: -------------------------------------------------------------------------------- 1 | /* General Styles */ 2 | body { 3 | font-family: Arial, sans-serif; 4 | margin: 0; 5 | padding: 0; 6 | background-color: #f4f4f9; 7 | color: #333; 8 | } 9 | 10 | /* Center Content */ 11 | .container { 12 | max-width: 600px; 13 | margin: 50px auto; 14 | padding: 20px; 15 | background: #fff; 16 | box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); 17 | border-radius: 8px; 18 | } 19 | 20 | /* Header */ 21 | h1 { 22 | font-size: 24px; 23 | text-align: center; 24 | margin-bottom: 20px; 25 | color: #555; 26 | } 27 | 28 | /* Paragraphs */ 29 | p { 30 | font-size: 16px; 31 | margin: 10px 0; 32 | text-align: center; 33 | } 34 | 35 | /* Form Styles */ 36 | form { 37 | display: flex; 38 | flex-direction: column; 39 | align-items: center; 40 | } 41 | 42 | label { 43 | font-size: 16px; 44 | margin-bottom: 10px; 45 | } 46 | 47 | input[type="number"], 48 | button { 49 | padding: 10px; 50 | margin: 10px 0; 51 | border: 1px solid #ccc; 52 | border-radius: 4px; 53 | font-size: 16px; 54 | width: 100%; 55 | max-width: 300px; 56 | } 57 | 58 | button { 59 | background-color: #007bff; 60 | color: white; 61 | border: none; 62 | cursor: pointer; 63 | } 64 | 65 | button:hover { 66 | background-color: #0056b3; 67 | } 68 | 69 | /* Results Section */ 70 | h2 { 71 | font-size: 20px; 72 | margin-top: 20px; 73 | text-align: center; 74 | color: #444; 75 | } 76 | 77 | /* Links */ 78 | a { 79 | display: block; 80 | text-align: center; 81 | margin-top: 20px; 82 | color: #007bff; 83 | text-decoration: none; 84 | } 85 | 86 | a:hover { 87 | text-decoration: underline; 88 | } -------------------------------------------------------------------------------- /templates/cek_usia.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |Tahun Lahir: {{ tahun_lahir }}
21 |Usia Anda: {{ usia }} tahun
22 | {% elif usia is not none and usia <= 0 %} 23 |Masukkan tahun lahir yang valid
24 | {% endif %} 25 | 26 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |Masukkan tahun lahir Anda untuk menghitung usia.
12 | Hitung Usia 13 | 14 | --------------------------------------------------------------------------------