Tuesday, March 26, 2024

Python : Basic Source Code to Create a Web Page Link to Display a Table

This source code will be further developed to display a table containing data from MariaDB.


This is the Python source code to connect two HTML pages through a web link :


 from flask import Flask, render_template, request, url_for, redirect  
 from jinja2 import Template, Environment, FileSystemLoader  
 import mariadb  
 import sys  
 aplikasi = Flask(__name__)  
 @aplikasi.route('/')  
 def halaman1():  
   return render_template("halaman1.html")  
 @aplikasi.route('/halaman2')  
 def halaman2():  
   return render_template("halaman2.html")  
 if __name__ == '__main__':  
   aplikasi.run(host='0.0.0.0',port=8543,debug=True)  

This is the source code for the first HTML page :


 <!DOCTYPE html>  
 <html>  
      <head>  
           <meta name="viewport" content="width=device-width, initial-scale=1">  
           <style>  
           </style>  
      </head>  
      <body>  
           <h1>Halaman 1</h1>  
                <a href="{{ url_for('halaman2')}}">Halaman 2</a>  
      </body>  
 </html>  

This is the source code for the second HTML page :


 <!DOCTYPE html>  
 <html>  
      <head>  
           <meta name="viewport" content="width=device-width, initial-scale=1">  
      </head>  
      <body>  
           <h1>Halaman 2</h1>  
           <a href="{{ url_for('halaman1')}}">Halaman 1</a>  
      </body>  
 </html>  

No comments:

Post a Comment