tag:blogger.com,1999:blog-1569458896183615252024-03-28T15:07:19.046+08:00Steven's BlogAnything You Can Find HereIT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-156945889618361525.post-25959238597318853642024-03-28T10:07:00.007+08:002024-03-28T15:06:46.719+08:00Python : Learning to Connect Between the OS Module and Flask<h1>We will start to integrate Flask with other Python programming code, in this case between Flask and the OS module.</h1>
<br>
<p>For the first one, we learn to use the OS module.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> import os
alamatFolder = os.getcwd()
print("Lokasi Folder Saat ini : ", alamatFolder)
</code></pre>
<p></p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> from flask import Flask, render_template, request, url_for, redirect
from jinja2 import Template, Environment, FileSystemLoader
import mariadb
import sys
import os
aplikasi = Flask(__name__)
@aplikasi.route('/')
def halaman1():
return render_template("halaman4.html")
if __name__ == '__main__':
aplikasi.run(host="0.0.0.0",port=8543,debug=True)
</code></pre>
IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-38270121056638112002024-03-27T09:09:00.003+08:002024-03-27T09:17:46.653+08:00JavaScript : Combining Python with Javascript to Run Python Source Code on an HTML PageWe are currently learning how to combine Python and Javascript programming code to run a command on a web page.
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> 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("halaman2.html")
if __name__ == '__main__':
aplikasi.run(host="0.0.0.0",port=8543,debug=True)
</code></pre>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.button {
background-color: #04AA6D;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: block;
font-size: 16px;
margin: 10px 10px;
cursor: pointer;
-webkit-transition-duration: 0.4s;
transition-duration: 0.4s;
}
.button2:hover {
box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}
</style>
</head>
<body>
<button class="button button2" onclick="document.getElementById('cetakTanggal').innerHTML = Date()">Uji Coba Javascript 1</button>
<p id="cetakTanggal"></p>
</body>
</html>
</code></pre>
<br>IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-56839707221690172832024-03-26T08:25:00.009+08:002024-03-26T08:40:11.726+08:00Python : Basic Source Code to Create a Web Page Link to Display a Table<h1>This source code will be further developed to display a table containing data from MariaDB.</h1>
<br>
<p>This is the Python source code to connect two HTML pages through a web link : </p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> 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)
</code></pre>
<br>
<p>This is the source code for the first HTML page : </p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!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>
</code></pre>
<br>
<p>This is the source code for the second HTML page : </p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!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>
</code></pre>
IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-62951906774090341182024-03-20T09:17:00.011+08:002024-03-20T10:45:38.117+08:00Python : Python Source Code for Menu Page, Data Entry Form, and Table Page for Data Display<h1>This is the menu page to display the data input menu, the data edit menu, and the menu to display a table containing the data.</h1>
<br>
<p>This is the source code for the menu page. The menu page is at the forefront and serves as a gateway to access various features in the application.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.vertical-menu {
width: 200px;
}
.vertical-menu a{
background-color: #eee;
color: black;
display: block;
padding: 12px;
text-decoration: none;
}
.vertical-menu a:hover {
background-color: #ccc;
}
.vertical-menu a.active{
background-color: #04AA6D;
color: white;
}
</style>
</head>
<body>
<h1>Vertical Menu</h1>
<div class="vertical-menu">
<a href="{{ url_for('halaman1')}}" class="active">Halaman Menu</a>
<a href="{{ url_for('halaman2')}}">Halaman Simpan Data</a>
<a href="{{ url_for('halaman3')}}">Halaman Edit Data</a>
<a href="{{ url_for('halaman4')}}">Halaman Tabel Data</a>
</div>
</body>
</html>
</code></pre>
<br>
<p>This is the source code for the data input page. There is also a button to display a table containing the data stored in the MariaDB table. There is also a button to return to the Menu page.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
input[type=text], select {
width: 100%;
padding: 12px 20px;
margin: 8px 0p;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
div {
border-radius: 5px;
background-color: #8ecaed;
padding: 20px;
}
</style>
</head>
<body>
<h1>Halaman Input Data</h1>
<div>
<form action="http://1.1.3.9:8543/halaman2" method="POST" id="formSimpanDataSurat" name="formSimpanDataSurat">
<label for="kodedatanomersurat1">Kode Data Nomer Surat</label>
<input type="text" id="kodedatanomersurat1" name="kodedatanomersurat1" placeholder="Isikan Kode Data Nomer Surat">
<label for="tanggalsurat1">Tanggal Surat</label>
<input type="text" id="tanggalsurat1" name="tanggalsurat1" placeholder="Isikan Tanggal Surat">
<label for="nomersurat1">Nomer Surat</label>
<input type="text" id="nomersurat1" name="nomersurat1" placeholder="Isikan Nomer Surat">
<label for="perihalsurat1">Perihal Surat</label>
<input type="text" id="perihalsurat1" name="perihalsurat1" placeholder="Isikan Perihal Surat">
<input type="submit" name="tombolPerintah" value="Simpan Data">
<input type="submit" name="tombolPerintah" value="Tampilkan Tabel Data">
<input type="submit" name="tombolPerintah" value="Kembali Ke Halaman Menu">
</form>
</div>
</body>
</html>
</code></pre>
<br>
<p>This is the HTML source code to display a table containing data from the MariaDB server.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
<style>
#dataNama {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#dataNama td, #dataNama th {
border: 1px solid #ddd;
padding: 8px;
}
#dataNama tr:nth-child(even){background-color: #f2f2f2;}
#dataNama tr:hover {background-color: #dataNama}
#dataNama th{
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #04AA6D;
color: white;
}
</style>
</head>
<body>
<table id="dataNama">
<!--- Ini adalah source code untuk membuat header table ---->
{% if hasil1 %}
<tr>
{% for key in hasil1[0] %}
<th>{{ key }}</th>
{% endfor %}
</tr>
{% endif %}
<!----- ini adalah source code untuk membuat isi tabel ------>
{% for isitabel in hasil1 %}
<tr>
{% for value in isitabel.values()%}
<td>{{ value }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</body>
</html>
</code></pre>
<br>
<p>This is the source code written in Python. This source code is used to control and run the features on the three web pages above.</p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> 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', methods=['GET','POST'])
def halaman2():
if request.method == 'POST':
if request.form['tombolPerintah'] == 'Simpan Data':
kodeDataNomerSurat1 = request.form.get('kodedatanomersurat1')
tanggalSurat1 = request.form.get('tanggalsurat1')
nomerSurat1 = request.form.get('nomersurat1')
perihalSurat1 = request.form.get('perihalsurat1')
koneksi = mariadb.connect(user="steven",password="kucing",host="1.1.3.9",port=3306,database="saham")
kursor = koneksi.cursor()
kursor.execute("INSERT INTO nomersurat(kodedatanomersurat,tanggalsurat,nomersurat,perihalsurat) VALUES (%s,%s,%s,%s)",(kodeDataNomerSurat1,tanggalSurat1,nomerSurat1,perihalSurat1))
koneksi.commit()
koneksi.close()
return redirect(url_for('halaman1'))
# elif request.form['tombolPerintah'] == 'Tampilkan Tabel Data':
elif request.form['tombolPerintah'] == 'Tampilkan Tabel Data':
koneksi = mariadb.connect(user="steven",password="kucing",host="1.1.3.9",port=3306,database="saham")
kursor = koneksi.cursor(dictionary=True)
kursor.execute("SELECT kodedatanomersurat,tanggalsurat,nomersurat,perihalsurat FROM nomersurat")
hasil = kursor.fetchall()
return render_template("halaman4.html",hasil1=hasil)
# elif request.form['tombolPerintah'] == 'Kembali Ke Halaman Menu':
elif request.form['tombolPerintah'] == 'Kembali Ke Halaman Menu':
return redirect(url_for('halaman1'))
return render_template("halaman2.html")
@aplikasi.route('/halaman3')
def halaman3():
return render_template("halaman3.html")
@aplikasi.route('/halaman4')
def halaman4():
return render_template("halaman4.html")
if __name__ == '__main__':
aplikasi.run(host="0.0.0.0",port=8543,debug=True)
</code></pre>
<br>
IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-22772177463163306792024-03-15T09:10:00.007+08:002024-03-15T09:45:39.858+08:00Python : Source Code of The Menu For Accessing The Data Entry Page<p>This is the HTML source code for a vertical menu. The menu contains a list of actions that can be performed on the data.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.vertical-menu{
width: 200px;
}
.vertical-menu a{
background-color: #eee;
color: black;
display: block;
padding: 12px;
text-decoration: none;
}
.vertical-menu a:hover {
background-color: #ccc;
}
.vertical-menu a.active {
background-color: #04AA6D;
color: white;
}
</style>
</head>
<body>
<h1>Vertical Menu</h1>
<div class="vertical-menu">
<a href="{{ url_for('halaman1')}}" class="active">Halaman Menu</a>
<a href="{{ url_for('halaman2')}}">Halaman Simpan Data</a>
<a href="#">Halaman 3</a>
<a href="#">Halaman 4</a>
<a href="#">Halaman 5</a>
</div>
</body>
</html>
</code></pre>
<br>
<p>This is the HTML source code for creating a form that will be used to fill data into the Mariadb server.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
<style>
input[type=text], select{
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover{
background-color: #45a049;
}
div{
border-radius: 5px;
background-color: #8ecaed;
padding: 20px;
}
</style>
</head>
<body>
<h1>Halaman Input Data</h1>
<di>
<form action="http://1.1.3.10:8543/halaman2" method="POST" id="formSimpanDataSurat" name="formSimpanDataSurat">
<label for="kodedatanomersurat1">Kode Data Nomer Surat</label>
<input type="text" id="kodedatanomersurat1" name="kodedatanomersurat1" placeholder="Isikan Kode Data Nomer Surat">
<label for="tanggalsurat1">Tanggal Surat</label>
<input type="text" id="tanggalsurat1" name="tanggalsurat1" placeholder="Isikan Tanggal Surat">
<label for="nomersurat1">Nomer Surat</label>
<input type="text" id="nomersurat1" name="nomersurat1" placeholder="Isikan Nomer Surat">
<label for="perihalsurat1">Perihal Surat</label>
<input type="text" id="perihalsurat1" name="perihalsurat1" placeholder="Isikan Perihal Surat">
<input type="submit" name="tombolPerintah" value="Simpan Data">
<input type="submit" name="tombolPerintah" value="Kembali Ke Halaman Menu">
</form>
</div>
</body>
</html>
</code></pre>
<br>
<p>This is the Python source code for displaying a menu, data entry page, and executing the data entry command from the form to the Mariadb database.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> 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', methods=['GET','POST'])
def halaman2():
if request.method == 'POST':
if request.form['tombolPerintah'] == 'Simpan Data':
kodeDataNomerSurat1 = request.form.get('kodedatanomersurat1')
tanggalSurat1 = request.form.get('tanggalsurat1')
nomerSurat1 = request.form.get('nomersurat1')
perihalSurat1 = request.form.get('perihalsurat1')
koneksi = mariadb.connect(user="steven",password="kucing",host="1.1.3.10",port=3306,database="saham")
kursor = koneksi.cursor()
kursor.execute("INSERT INTO nomersurat(kodedatanomersurat,tanggalsurat,nomersurat,perihalsurat) VALUES (%s,%s,%s,%s)",(kodeDataNomerSurat1,tanggalSurat1,nomerSurat1,perihalSurat1))
koneksi.commit()
koneksi.close()
return redirect(url_for('halaman1'))
elif request.form['tombolPerintah'] == 'Kembali Ke Halaman Menu':
return redirect(url_for('halaman1'))
# return redirect(url_for('halaman1'))
return render_template('halaman2.html')
if __name__ == '__main__':
aplikasi.run(host="0.0.0.0",port=8543,debug=True)
</code></pre>
IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-82836894765759281542024-03-14T10:35:00.007+08:002024-03-14T10:55:25.212+08:00Python : This is An Example of Source Code That Inspires How to Create Menus and Links.<h1>This is the source code for displaying a menu that already uses CSS. This source code example is taken from a source on the internet.</h1>
<br>
<h2>HTML Source Code</h2>
<br>
<h3>HTML Source Code For Page 1</h3>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
<p><a href="{{ url_for('halaman2')}}">Coba anda lihat form ini</a></p>
</body>
</html>
</code></pre>
<br>
<h3>HTML Source Code For Page 2</h3>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
<form method="post">
<button type="submit">Uji Coba</button>
</form>
</body>
</html>
</code></pre>
<br>
<h3>Python Code : </h3>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> from flask import Flask, request, url_for, redirect, render_template
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', methods=['GET','POST'])
def halaman2():
if request.method == 'POST':
# lakukan sesuatu ketika form di kumpulkan
# dialihkan untuk mengakhiri penanganan POST
# pengalihan bisa ke route yang sama atau ke sesuatu yang lain
return redirect(url_for('halaman1'))
# tampilkan form nya, form nya tidak di kumpulkan
return render_template('halaman2.html')
if __name__ == '__main__':
aplikasi.run(host='0.0.0.0',port=8543,debug=True)
</code></pre>
IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-53287454391777800602024-03-14T10:06:00.007+08:002024-03-14T10:15:35.827+08:00Python : Learning How To Create A Menu And Link It To Routes To Open Different Pages.<h1>This is the source code for an HTML page containing a menu </h1>
<br>
<h2>HTML Code : </h2>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.vertical-menu{
width: 200px;
}
.vertical-menu a{
background-color: #eee;
color: black;
display: block;
padding: 12px;
text-decoration: none;
}
.vertical-menu a:hover {
background-color: #ccc;
}
.vertical-menu a.active {
background-color: #04AA6D;
color: white;
}
</style>
</head>
<body>
<h1>Vertical Menu</h1>
<div class="vertical-menu">
<a href="#" class="active">Halaman Utama</a>
<a href="#">Halaman 1</a>
<a href="#">Halaman 2</a>
<a href="#">Halaman 3</a>
<a href="#">Halaman 4</a>
</div>
</body>
</html>
</code></pre>
<br>
<h2>Python Code : </h2>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> from flask import Flask, render_template, request
from jinja2 import Template, Environment, FileSystemLoader
aplikasi = Flask(__name__)
@aplikasi.route('/')
def tampilHalaman():
return render_template("halaman1.html")
if __name__ == '__main__':
aplikasi.run(host="0.0.0.0",port=8543,debug=True)
</code></pre>
IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-85186799931978019892024-02-21T10:57:00.036+08:002024-03-08T09:52:41.801+08:00Python : Exercises on Using Dictionaries in Python<h1>The following are exercises on using Dictionaries in Python that have been completed today.</h1>
<br>
<p><b>file14.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> kamusku = {}
kamusku['nama'] = "Steven Nathaniel"
kamusku['usia'] = 1
print (kamusku)
</code></pre>
<br>
<p><b>file15.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> kamusku = {}
print(kamusku)
print(type(kamusku))
</code></pre>
<br>
<p><b>file16.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> informasi = {'nama':'steven','usia':15,'lokasi':'Athena'}
print(informasi)
print(type(informasi))
</code></pre>
<br>
<p><b>file17.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> informasi = dict({'nama':'steven','usia':15,'lokasi':'Athena'})
print(informasi)
print(type(informasi))
</code></pre>
<br>
<p><b>file18.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> namaKota = ('Samarinda','Athena','Balikpapan')
kamusKu = dict.fromkeys(namaKota)
print(kamusKu)
</code></pre>
<br>
<p><b>file19.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> namaKota = ('Balikpapan','Samarinda','Jakarta')
negara = 'Indonesia'
kamus = dict.fromkeys(namaKota,negara)
print(kamus)
</code></pre>
<br>
<p><b>file20.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> namaKota = ('Balikpapan','Samarinda','Jakarta')
negara = 'indonesia'
kamus = dict.fromkeys(namaKota,negara)
print(len(kamus))
</code></pre>
<br>
<p><b>file21.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> tahunPembuatanMobil = {'Kijang': 1997, 'Lancer': 1995, 'Accord': 1999}
print(tahunPembuatanMobil.values())
</code></pre>
<br>
<p><b>file22.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> dataRoti = {'merekRoti': 'Sari Roti', 'tanggalProduksi': 22, 'bulanProduksi': 'Februari'}
print(dataRoti['merekRoti'])
</code></pre>
<br>
<p><b>file23.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> dataRoti = {'merekRoti': 'Sari Roti', 'tanggalProduksi': 22, 'bulanProduksi': 'Februari'}
print('merekNasi' in dataRoti)
</code></pre>
<br>
<p><b>file24.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> dataRoti = {'merekRoti': 'Sari Roti', 'tanggalProduksi': 22, 'bulanProduksi': 'Februari'}
print(dataRoti.get('merekRoti'))
</code></pre>
<br>
<p><b>file25.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> dataRoti = {}
dataRoti["namaRoti"] = "Roti Bakar Kepiting"
print(dataRoti)
</code></pre>
<br>
<p><b>file26.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> dataRoti = {}
dataRoti['namaRoti'] = "Roti Bakar Mentega"
dataRoti['jumlahRoti'] = 10
print(dataRoti)
</code></pre>
<br>
<p><b>file27.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> dataRoti = {'namaRoti':"Roti Bakar Mentega", 'jumlahRoti':9}
print(dataRoti)
dataRoti['jumlahRoti'] = 11
print(dataRoti)
</code></pre>
<br>
<p><b>file28.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> dataRoti = {'namaRoti':"Roti Goreng Mentega",'kemasanRoti':"Plastik"}
print(dataRoti)
dataRoti['kemasanRoti'] = "Kayu"
print('kemasanRoti' in dataRoti)
</code></pre>
<br>
<p><b>file29.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> dataRoti = {'merekRoti':"Bondy", 'jumlahLembar':10}
dataRoti.update(merekRoti='Holland', jumlahLembar=50, penggunaanKulit='Kulit')
print(dataRoti)
</code></pre>
<br>
<p><b>file30.py</b></p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> dataRoti = {'merekRoti':'Bondy','bulanPembuatan':'Februari','lokasiToko':'Gunung Sari'}
del dataRoti['bulanPembuatan']
print(dataRoti)
</code></pre>
<br>
<p>This is a source code that almost successfully displays data from the database into a table format.</p>
<br>
<p>This is the source code for the Python section.</p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> import mariadb
import sys
from jinja2 import Template, Environment, FileSystemLoader
from flask import Flask, render_template, request
aplikasi = Flask(__name__)
@aplikasi.route('/')
def tampilkanData():
koneksi = mariadb.connect(user="steven",password="kucing",host="1.1.3.7",port=3306,database="saham")
kursor = koneksi.cursor(dictionary=True)
kursor.execute("SELECT idnama1,namaawal1,namaakhir1 FROM nama1")
hasil = kursor.fetchall()
koneksi.commit()
koneksi.close()
return render_template("halaman6.html",hasil=hasil)
if __name__ == '__main__':
aplikasi.run(host="0.0.0.0", port=8543, debug=True)
</code></pre>
<br>
<p>This is the source code for the HTML section.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Tampilkan Tabel</h1>
<table>
{% for hasil_item in hasil %}
{% for key, value in hasil_item.items() %}
<tr>
<th>{{ key }}</th>
</tr>
<tr>
<td>{{ value }}</td>
</tr>
{% endfor %}
{% endfor %}
</table>
</body>
</html>
</code></pre>
<br>
<p>This is the working source code to display the contents of a dictionary from the results of a database query. The data is displayed on an HTML page. This is an example of source code that uses HTML and Python.</p>
<br>
<p><b>HTML : </b></p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
{{ hasil1[0] }}
</body>
</html>
</code></pre>
<br>
<p>This is an example of an HTML source code that displays the entire contents of a dictionary.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
{{ hasil1 }}
</body>
</html>
</code></pre>
<br>
<p>The following are variations of HTML source code that will display different data results.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
{% for hasil2 in hasil1 %}
{% for key, value in hasil2.items() %}
{{ value }}
{% endfor %}
{% endfor %}
</body>
</html>
</code></pre>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
{% for hasil2 in hasil1 %}
{{ hasil2.keys() }}
{% endfor %}
</body>
</html>
</code></pre>
<br>
<p>This is the source code that successfully displays data in an HTML table correctly.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE HTML>
<HTML>
<HEAD>
</HEAD>
<BODY>
<table>
<!----- Ini adalah source code untuk membuat header table ----->
{% if hasil1 %}
<tr>
{% for key in hasil1[0] %}
<th> {{ key }} </th>
{% endfor %}
</tr>
{% endif %}
<!--- Ini adalah source code untuk membuat isi tabel -->
{% for isitabel in hasil1 %}
<tr>
{% for value in isitabel.values() %}
<td>{{ value }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</BODY>
</HTML>
</code></pre>
<br>
<p>This is a combination of querying the correct database and displaying the correct table (using CSS).</p>
<p><b>Python Code : </b></p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> from flask import Flask, render_template, request
from jinja2 import Template, Environment, FileSystemLoader
import mariadb
import sys
aplikasi = Flask(__name__)
@aplikasi.route('/')
def tabelData():
koneksi = mariadb.connect(user="steven",password="kucing",host="1.1.3.7",port=3306,database="saham")
kursor = koneksi.cursor(dictionary=True)
kursor.execute("SELECT idnama1,namaawal1,namaakhir1 FROM nama1")
hasil = kursor.fetchall()
return render_template("halaman11.html",hasil1=hasil)
if __name__ == '__main__':
aplikasi.run(host="0.0.0.0", port=8543, debug=True)
</code></pre>
<br>
<p><b>HTML Code : </b></p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
<style>
#dataNama {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#dataNama td, #dataNama th {
border: 1px solid #ddd;
padding: 8px;
}
#dataNama tr:nth-child(even){background-color: #f2f2f2;}
#dataNama tr:hover {background-color: #dataNama}
#dataNama th{
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #04AA6D;
color: white;
}
</style>
</head>
<body>
<table id="dataNama">
<!------- Ini adalah source code untuk membuat header table -------->
{% if hasil1 %}
<tr>
{% for key in hasil1[0] %}
<th> {{ key }} </th>
{% endfor %}
</tr>
{% endif %}
<!--- ini adalah source code untuk membuat isi tabel -->
{% for isitabel in hasil1 %}
<tr>
{% for value in isitabel.values() %}
<td>{{ value }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
</body>
</html>
</code></pre>
<br>
IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-69596821827248429302024-02-19T10:22:00.012+08:002024-02-20T15:52:04.025+08:00Python: Source Code That Successfully Displays Data in a Table<h1>This is the basic source code that can display data from a MariaDB table.</h1>
<p>This is the source code that has successfully displayed data into an HTML table.</p>
<p>This is source for python : </p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> from flask import Flask, render_template, request
from jinja2 import Template, Environment, FileSystemLoader
import mariadb
import sys
aplikasi = Flask(__name__)
@aplikasi.route('/')
def tabelData1():
return render_template("halaman2.html",)
@aplikasi.route('/tampilData',methods=['POST'])
def tampilkanData():
if request.method=='POST':
if request.form['tombolPerintah'] == 'Tampilkan Data':
koneksi = mariadb.connect(user="steven",password="kucing",host="1.1.3.13",port=3306,database="saham")
kursor = koneksi.cursor(dictionary=True)
kursor.execute("SELECT idnama1,namaawal1,namaakhir1 FROM nama1")
hasil = kursor.fetchall()
# print(hasil)
# Tampilkan isi Baris pertama dari tabel
idnama1 = hasil[0]["idnama1"]
namaawal1 = hasil[0]["namaawal1"]
namaakhir1 = hasil[0]["namaakhir1"]
# Tampilkan isi Baris kedua dari tabel
idnama2 = hasil[1]["idnama1"]
namaawal2 = hasil[1]["namaawal1"]
namaakhir2 = hasil[1]["namaakhir1"]
return render_template("halaman2.html", IdNama1 = idnama1, NamaAwal1 = namaawal1, NamaAkhir1 = namaakhir1, IdNama2 = idnama2, NamaAwal2 = namaawal2, NamaAkhir2 = namaakhir2)
koneksi.commit()
koneksi.close()
if __name__ == '__main__':
aplikasi.run(host='0.0.0.0',port=8543,debug=True)
</code></pre>
<br>
<p>This is source code for HTML page : </p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
<h3>Tabel Menampilkan Data</h3>
<form action="http://1.1.3.13:8543/tampilData" method="POST" id="formMenampilkanData" name="formMenampilkanData">
<table>
<thead>
<tr>
<th>ID Nama</th>
<th>Nama Awal</th>
<th>Nama Akhir</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ IdNama1}}</td>
<td>{{ NamaAwal1 }}</td>
<td>{{ NamaAkhir1 }}</td>
</tr>
<tr>
<td>{{ IdNama2 }}</td>
<td>{{ NamaAwal2 }}</td>
<td>{{ NamaAkhir2 }}</td>
</tr>
</tbody>
</table>
<input type="submit" name="tombolPerintah" value="Tampilkan Data">
</form>
</body>
</html>
</code></pre>
<br>
<a href="https://pythonexamples.org/python-flask-for-loop-in-html-template/">This is a link that contains an example of how to create a loop, in an effort to display data in a table. </a>
<p>Next, we will try to be able to create a table using this looping function.</p>
<p>This source code successfully displays data based on the looping results, but the data is still in the form of a list, not data that can be separated by rows and columns.</p>
<p>We will use the Dictionary concept to collect data from Mariadb. The data is the result of a query process from Mariadb. The Dictionary will be tried to be used to build a table on an HTML page.</p>
<a href="https://blog.miguelgrinberg.com/post/beautiful-interactive-tables-for-your-flask-templates">This is an example of a link that can help you display data in an HTML table.</a>
<br>
<a href="https://www.freecodecamp.org/news/create-a-dictionary-in-python-python-dict-methods/">This link is suitable for learning in depth about dictionaries.</a>
IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-23612987519619517012024-02-13T16:32:00.004+08:002024-02-13T16:34:37.928+08:00Wifi Sharing : How to Share a WiFi Connection Using a Cheap USB Dongle Like Tenda and Totolink<p>Here are the steps on how to share internet from a laptop or PC using a USB WiFi Dongle. This will allow other devices to connect to the internet as well.</p>
<br>
netsh wlan set hostednetwork mode=allow ssid=nasipecel key=makan1234 keyusage=temporary
<br>
netsh wlan start hostednetwork
<br>
netsh wlan show hostednetwork
<br>
netsh wlan set hostednetwork mode=disallow
<br>
netsh wlan stop hostednetwork
<br>
netsh wlan show settings
<br>
netsh wlan show profiles
<br>
netsh wlan delete profile name="swisscom"
<br>
netsh wlan delete profile name=* i=*
<br>
netsh wlan show drivers
<br>
https://stackoverflow.com/questions/18182084/cant-start-hostednetwork
<br>
https://support.airserver.com/support/solutions/articles/43000532725-how-can-i-enable-the-wireless-autoconfig-service-the-wireless-autoconfig-service-wlansvc-is-not-
<br>
https://youtu.be/2pvK-6321ig?si=tKonB-Tn-LIvcTTXIT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-74259832931243009482024-02-13T12:01:00.003+08:002024-02-13T12:09:06.020+08:00Python Flask : Getting Ready to Make a Table<p>The source code below is to start finding ways to create a table on a web page. The data for the table is taken from a MariaDB database query.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> from jinja2 import Template, Environment, FileSystemLoader
from flask import Flask, render_template, request, json, jsonify
import mariadb
import sys
aplikasi = Flask(__name__)
@aplikasi.route('/')
def formUtama():
return render_template("halaman1.html")
@aplikasi.route('/tampilData',methods=['POST'])
def tampilkanData():
if request.method=='POST':
koneksi = mariadb.connect(user="steven",password="kucing",host="1.1.3.9",port=3306,database="saham")
kursor= koneksi.cursor(dictionary=True)
kursor.execute("SELECT kodedata,tanggalpendataan,kodebarang,NIP,namabarang,kodebagian,namadivisi,merekprinter,serialprinter,macaddress,jenistinta,namapengguna FROM daftartintaprinter2")
hasil = kursor.fetchall()
# di bawah ini untuk menampilkan baris data yang urutan 1
kodedata1 = hasil[0]["kodedata"]
tanggalpendataan1 = hasil[0]["tanggalpendataan"]
kodebarang1 = hasil[0]["kodebarang"]
nip1 = hasil[0]["NIP"]
namabarang1 = hasil[0]["namabarang"]
kodebagian1 = hasil[0]["kodebagian"]
namadivisi1 = hasil[0]["namadivisi"]
merekprinter1 = hasil[0]["merekprinter"]
serialprinter1 = hasil[0]["serialprinter"]
macaddress1 = hasil[0]["macaddress"]
jenistinta1 = hasil[0]["jenistinta"]
namapengguna1 = hasil[0]["namapengguna"]
# di bawah ini untuk menampilkan baris data yang urutan 2
kodedata2 = hasil[1]["kodedata"]
tanggalpendataan2 = hasil[1]["tanggalpendataan"]
kodebarang2 = hasil[1]["kodebarang"]
nip2 = hasil[1]["NIP"]
namabarang2 = hasil[1]["namabarang"]
kodebagian2 = hasil[1]["kodebagian"]
namadivisi2 = hasil[1]["namadivisi"]
merekprinter2 = hasil[1]["merekprinter"]
serialprinter2 = hasil[1]["serialprinter"]
macaddress2 = hasil[1]["macaddress"]
jenistinta2 = hasil[1]["jenistinta"]
namapengguna2 = hasil[1]["namapengguna"]
koneksi.commit()
koneksi.close()
return render_template("halaman3.html", kodeData1 = kodedata1, tanggalPendataan1 = tanggalpendataan1, kodeBarang1 = kodebarang1, NIP1 = nip1, namaBarang1 = namabarang1, kodeBagian1 = kodebagian1, namaDivisi1 = namadivisi1, merekPrinter1 = merekprinter1, serialPrinter1 = serialprinter1, macAddress1 = macaddress1, jenisTinta1 = jenistinta1, namaPengguna1 = namapengguna1, kodeData2 = kodedata2, tanggalPendataan2 = tanggalpendataan2, kodeBarang2 = kodebarang2, NIP2 = nip2, namaBarang2 = namabarang2, kodeBagian2 = kodebagian2, namaDivisi2 = namadivisi2, merekPrinter2 = merekprinter2, serialPrinter2 = serialprinter2, macAddress2 = macaddress2, jenisTinta2 = jenistinta2, namaPengguna2 = namapengguna2 )
if __name__ == '__main__':
aplikasi.run(host='0.0.0.0',port=8543,debug=True)
</code></pre>
<br>
<p></p>IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-32350750047583117892024-02-07T09:56:00.007+08:002024-02-07T10:01:31.475+08:00Getting Started with PHP Programming<h1>Getting Started with PHP Programming</h1>
<p>Resuming Our PHP Learning Journey in Laravel. Below is a simple source code example to get you started with learning PHP programming again.</p>IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-16356100361573905372024-01-30T11:51:00.010+08:002024-01-31T16:23:56.292+08:00Flask: Printing Database Query Results to an HTML Table<p>In this example, I am trying to query a <b>MariaDB</b> database. Then I am trying to display the results on a web page. However, for the first step, I will try to display the query results to the terminal. The following is the source code for printing database query results to the terminal: </p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> import mariadb
import sys
koneksi = mariadb.connect(user="steven",password="kucing",host="1.1.3.6",port=3306,database="saham")
kursor = koneksi.cursor(dictionary=True)
kursor.execute("SELECT idnama1,namaawal1,namaakhir1 FROM nama1")
hasil = kursor.fetchall()
print(hasil[0])
</code></pre>
<br>
<p>The following source code successfully prints the query results from the MariaDB database to the terminal.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> import mariadb
import sys
koneksi = mariadb.connect(user="steven",password="kucing",host="1.1.3.7",port=3306,database="saham")
kursor = koneksi.cursor(dictionary=True)
kursor.execute("SELECT idnama1,namaawal1,namaakhir1 FROM nama1")
hasil = kursor.fetchall()
print(hasil[1])
</code></pre>
<br>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> import mariadb
import sys
koneksi = mariadb.connect(user="steven",password="kucing",host="1.1.3.7",port=3306,database="saham")
kursor = koneksi.cursor(dictionary=True)
kursor.execute("SELECT idnama1,namaawal1,namaakhir1 FROM nama1")
hasil = kursor.fetchall()
idnama1A = hasil[0]["idnama1"]
print(idnama1A)
</code></pre>
<br>
<p>The following is the source code for rendering an HTML page using Flask.</p>
<br>
<br>
IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-80383618922149534672024-01-11T10:53:00.004+08:002024-01-11T14:30:39.920+08:00Python 3 : The Class<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> class kelas1:
def __init__(self, nama, usia):
self.nama = nama
self.usia = usia
def __str__(self):
return "Tampilkan nama : %s , usia : %s" % (self.nama, self.usia)
isian = kelas1("Steven", 17)
print(isian)
</code></pre>
<h1>This is the Initial Source Code for Learning About Classes in Python Programming.</h1>
<p>Understanding classes in Python programming will be useful for understanding how to create tables using <b>Flask Table</b>.</p>
<p>A class is a group of functions.</p>
<p>We want to learn how to inherit in classes in Python programming. We can only inherit within the same class, which is inheritance between functions.</p>IT Writerhttp://www.blogger.com/profile/10445657762034183360noreply@blogger.com0tag:blogger.com,1999:blog-156945889618361525.post-80171865543371129062023-11-12T10:52:00.085+08:002023-11-27T09:22:36.919+08:00This Blog will be Written in a Language Other Than Indonesian<p><span style="font-family: arial;"> </span></p><p></p><div class="separator" style="clear: both; text-align: center;"><span style="font-family: arial;"><iframe allowfullscreen="" class="BLOG_video_class" height="266" src="https://www.youtube.com/embed/H_Fnd4aInHI" width="320" youtube-src-id="H_Fnd4aInHI"></iframe></span></div><span style="font-family: arial;"><br /></span><p></p><p><span style="font-family: arial;">There will be a change in the language used on this blog, from Indonesian to a language other than Indonesian. <span style="background-color: white; color: #1f1f1f; white-space-collapse: preserve;">In this blog, I will write about various things. </span></span></p><p><span style="background-color: white; color: #1f1f1f; white-space-collapse: preserve;"><span style="font-family: arial;">I have successfully compressed the size of a .jpeg photo file using the following software:</span></span></p><p><span style="background-color: white; white-space-collapse: preserve;"><span style="color: #1f1f1f; font-family: arial;"><a href="https://saerasoft.com/caesium/">https://saerasoft.com/caesium/</a></span></span></p><p><span style="font-family: arial;"><span style="background-color: white; color: #1f1f1f; white-space-collapse: preserve;">And in one article, I will try to achieve a target of 800 words or more. </span><span style="background-color: white; color: #1f1f1f; white-space-collapse: preserve;">What I have learned in the past two days is about the applications <b>Snackvideo</b> and <b>Bigo Live</b>. </span><span style="color: #1f1f1f;"><span style="white-space-collapse: preserve;">The applications SnackVideo and Bigo seem to be more lenient than TikTok in terms of regulations. As a result, there are not many violations in both of these applications. </span></span><span style="color: #1f1f1f;"><span style="white-space-collapse: preserve;">Some users who perform live streaming on Bigo have moved their live streaming activities to the <b>Line</b> application. Perhaps this is because the rules on the Line application are more lenient than on Bigo. This is a rule related to the issue of nudity. </span></span><span style="background-color: white; color: #1f1f1f; white-space-collapse: preserve;">In the Bigo app, in some live rooms, there are live room administrators who will remove viewers who only watch without giving any gifts to the host of the live room.</span></span></p><p><span style="font-family: arial;"><span><span style="background-color: white; color: #1f1f1f; white-space-collapse: preserve;">Today I have successfully changed the address of my blog to .<span class="animating">web.</span><span class="animating">id.</span><span class="animating"> I have also successfully connected it to <b>AdSense</b>. I am always learning how to make the links from my blog to be on various websites. In the afternoon, I studied about writing programming code using the Python programming language. The <b>Python</b> programming code was run in the <b>Docker </b>application. I have also successfully set up <b>Google Analytics</b> on this blog. </span></span></span><span style="background-color: white; color: #1f1f1f; white-space-collapse: preserve;">I have already submitted this blog to <b>Bing Webmaster</b> and <b>Yandex Webmaster</b>, so this blog is also indexed in both of those search engines.</span></span></p><p><span style="font-family: arial;"></span></p><div class="separator" style="clear: both; text-align: center;"><span style="font-family: arial;"><iframe allowfullscreen="" class="BLOG_video_class" height="266" src="https://www.youtube.com/embed/5AaxcwVGKjY" width="320" youtube-src-id="5AaxcwVGKjY"></iframe></span></div><span style="font-family: arial;"><br /></span><p></p>
<h3><span style="font-family: arial; font-size: small;">Building Docker Image</span></h3>
<p><span style="font-family: arial;">Here is the command to build a Docker image. Type the following command in the terminal of the host computer that has Docker : </span></p>
<span style="font-family: arial;"><!--HTML generated using hilite.me--></span><div style="background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;"><pre style="line-height: 125%; margin: 0px;"><span style="font-family: arial;">sudo docker image build <span style="color: #333333;">-</span>t python<span style="color: #333333;">-</span>flask2 <span style="color: #333333;">/</span>home<span style="color: #333333;">/</span>steven<span style="color: #333333;">/</span>proyekPython<span style="color: #333333;">/</span>latihan1
</span></pre></div>
<p><span style="font-family: arial;">Here is the command to find out who the user is in the specified Docker image: </span></p>
<span style="font-family: arial;"><!--HTML generated using hilite.me--></span><div style="background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;"><pre style="line-height: 125%; margin: 0px;"><span style="font-family: arial;">sudo docker run <span style="color: #333333;">--</span>entrypoint <span style="background-color: #fff0f0;">""</span> python<span style="color: #333333;">-</span>mariadb1 whoami
</span></pre></div>
<p><span style="font-family: arial;">The following command will remove a Docker image that has already been built : </span></p>
<span style="font-family: arial;"><!--HTML generated using hilite.me--></span><div style="background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;"><pre style="line-height: 125%; margin: 0px;"><span style="font-family: arial;">sudo docker image rm <span style="color: #333333;"><</span>nama<span style="color: #333333;">-</span>repository<span style="color: #333333;">></span>
</span></pre></div>
<p><span style="font-family: arial;">The following command will list all containers that have been created : </span></p>
<span style="font-family: arial;"><!--HTML generated using hilite.me--></span><div style="background: rgb(255, 255, 255); border-color: gray; border-image: initial; border-style: solid; border-width: 0.1em 0.1em 0.1em 0.8em; border: solid gray; overflow: auto; padding: 0.2em 0.6em; width: auto;"><pre style="line-height: 125%; margin: 0px;"><span style="font-family: arial;">sudo docker ps <span style="color: #333333;">-</span>a
</span></pre></div>
<p><span style="font-family: arial;">Instructions for deleting a container : </span></p>
<p><span style="font-family: arial;"> sudo docker container rm (ID Container)</span></p>
<p><b><span style="font-family: arial;">Example : </span></b></p>
<p><span style="font-family: arial;"> sudo docker container rm 9c9b1210e0c0</span></p>
<span style="font-family: arial;"><br />
</span><p><span style="font-family: arial;">Instructions for running a Docker image on a <b>Lokinet</b> network : </span></p>
<p><span style="font-family: arial;">sudo docker run -p 0.0.0.0:8543:8543 python-flask1</span></p>
<span style="font-family: arial;"><br />
</span><p><span style="font-family: arial;">command to stop a running container : </span></p>
<p><span style="font-family: arial;">sudo docker container stop (ID Container) </span></p>
<p><b><span style="font-family: arial;">Example :</span></b></p>
<p><span style="font-family: arial;">sudo docker container stop b4d3e8d5fe4a</span></p><p><span style="font-family: arial;"><br /></span></p><p><span style="background-color: white; color: #1f1f1f; white-space-collapse: preserve;"><span style="font-family: arial;">Instructions to run a docker image on multiple ports simultaneously:</span></span></p><p><span style="font-family: arial;">sudo docker run -p 0.0.0.0:3306:3306 -p 0.0.0.0:8543:8543 -t python-mariadb1 </span></p><p><span style="font-family: arial;">Here is the source code for a web project using the Python programming language in Docker, which also includes the help of the Jinja2 library, Blueprint :</span></p><p><span style="font-family: arial;"><span style="background-color: white; color: #1f1f1f; white-space-collapse: preserve;">At the beginning, I will write the programming code for the Docker file, this programming code can also give commands to Docker to create a templates folder.</span></span></p><p><span style="font-family: arial;"><span style="background-color: white; color: #1f1f1f; white-space-collapse: preserve;"><br /></span></span></p><p><br /></p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> FROM python
USER 0
WORKDIR /home
# RUN cd /home
RUN mkdir ./templates
EXPOSE 3306 8543
RUN pip install flask
RUN pip install Jinja2
RUN pip install mariadb
COPY file4.py ./
COPY file1.html ./templates
CMD ["python3", "./file4.py"]
</code></pre>
<br>
<p>Here is the source code for the HTML template that becomes the user interface of our program : </p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{{title}}</title>
</head>
<body>
<h1>Selamat Datang Di {{kota}}</h1>
</body>
</html>
</code></pre>
<br>
<p>Here is the Python source code for running a program that can display text on a web page. With the help of Jinja templates and routing from blueprints.</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> from jinja2 import Environment, FileSystemLoader
from flask import Flask, render_template
aplikasi = Flask(__name__)
@aplikasi.route('/')
def halamanPertama():
return render_template("file1.html",title="New Found Land",kota="Land")
if __name__ == '__main__':
aplikasi.run(host='0.0.0.0',port='8543',debug='True')
</code></pre>
<br>
<h2>Latihan 2</h2>
<p>The following source code is the Docker file for Exercise 2 : </p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> FROM python
USER 0
WORKDIR /home
RUN mkdir ./latihan2
RUN mkdir ./latihan2/templates
EXPOSE 3306 8543
RUN pip install flask
RUN pip install Jinja2
RUN pip install mariadb
COPY file1.py ./latihan2
COPY file1.html ./latihan2/templates
CMD ["python3", "./latihan2/file1.py"]
</code></pre>
<br>
<p>The HTML file for the following application interface:</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>Kode Data : {{kodedata}}</p>
<p>Tanggal Pendataan : {{tanggalpendataan}}</p>
<p>Bagian/Sub Bagian : {{bagiansubbagian}}</p>
<p>Kode Barang : {{kodebarang}}</p>
<p>Merek Printer : {{merekprinter}}</p>
</body>
</html>
</code></pre>
<br>
<p>Here is the Python source code for creating the core application of the program we made</p>
<br>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> import mariadb
import sys
import json
from jinja2 import Environment, FileSystemLoader
from flask import Flask, render_template
aplikasi = Flask(__name__)
try:
koneksi = mariadb.connect(user="steven",password="kucing",host="1.1.3.9",port=3306,database="saham")
except mariadb.Error as e:
print(f"Gagal Terkoneksi Ke : {e}")
sys.exit(1)
kursor = koneksi.cursor()
kursor.execute("SELECT kodedata,tanggalpendataan,bagiansubbagian,kodebarang,merekprinter FROM daftartintaprinter")
hasil = kursor.fetchall()
for data in hasil:
kodedata = data[0]
tanggalpendataan = data[1].strftime("%Y-%m-%d")
bagiansubbagian = data[2]
kodebarang = data[3]
merekprinter = data[4]
f = lambda s: f"dict({','.join(f'{k}={k}' for k in s.split(','))})"
kamusHasil = eval(f('kodedata,tanggalpendataan,bagiansubbagian,kodebarang,merekprinter'))
@aplikasi.route('/')
def halamanUtama():
return render_template("file1.html", **kamusHasil)
if __name__ == '__main__':
aplikasi.run(host='0.0.0.0', port=8543, debug=True)
</code></pre>
<br>
<br>
<p> The following is a link to a lesson on how data transfer can happen in <b>Flask</b> and <b>Jinja</b> : </p>
<a href="https://pythonbasics.org/flask-template-data/" target="_blank">https://pythonbasics.org/flask-template-data/</a>
<br>
<br>
<h1>Latihan 5</h1>
<p>The following source code is the Docker file for Exercise 5 :</p>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> FROM python
USER 0
WORKDIR /home
RUN mkdir ./latihan5
RUN mkdir ./latihan5/templates
EXPOSE 3306 8543
RUN pip install flask
RUN pip install Jinja2
RUN pip install mariadb
COPY file1.py ./latihan5
COPY murid1.html ./latihan5/templates
COPY hasil1.html ./latihan5/templates
CMD ["python3", "./latihan5/file1.py"]
</code></pre>
<br>
<p>Here, we write the code to create a simple form, which later can be used for data transfer experiments using Flask and Jinja.</p>
<br>
<h2>murid1.html</h2>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action = "http://1.1.3.2:8543/hasil" method = "POST">
<p>Nama : <input type="text" name="Nama"/></p>
<p><input type = "submit" value = "submit"></p>
</form>
</body>
</html>
</code></pre>
<br>
<p>The following is the source code to receive data input from the <b>murid1.html</b> page and then display the input results to the <b>hasil1.html</b> page.</p>
<br>
<h2>file1.py</h2>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> from flask import Flask, render_template, request
aplikasi = Flask(__name__)
@aplikasi.route('/')
def murid():
return render_template('murid1.html')
@aplikasi.route('/hasil',methods = ['POST','GET'])
def hasil():
if request.method == 'POST':
hasil = request.form
return render_template("hasil1.html",hasil = hasil)
if __name__ == '__main__':
aplikasi.run(host='0.0.0.0', port=8543, debug=True)
</code></pre>
<br>
<p>The following is the source code to display the results of the data entry activity performed in the form on the murid1.html page.</p>
<br>
<h2>hasil1.html</h2>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
<table border=1>
{% for key, value in hasil.items() %}
<tr>
<th>{{ key }}</th>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>
</body>
</html>
</code></pre>
<br>
<p>In the following source code, we have successfully displayed the results of the input data that was performed in the HTML form in JSON format. We will use the JSON data transfer format because we will be using a RESTful API.</p>
<h2>Latihan 6</h2>
<h3>Dockerfile</h3>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> FROM python
USER 0
WORKDIR /home
RUN mkdir ./latihan6
RUN mkdir ./latihan6/templates
EXPOSE 3306 8543
RUN pip install flask
RUN pip install Jinja2
RUN pip install mariadb
COPY file1.py ./latihan6
COPY form1.html ./latihan6/templates
CMD ["python3", "./latihan6/file1.py"]
</code></pre>
<br>
<h3>file1.py</h3>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> from flask import Flask, render_template, request, jsonify, json
aplikasi = Flask(__name__)
@aplikasi.route('/')
def formulirIsiData():
return render_template('form1.html')
@aplikasi.route('/tampilData',methods = ['POST'])
def tampilkanData():
if request.method == 'POST':
# tampilkanData = request.form
# nama = request.form['nama']
# return print (tampilkanData)
# di bawah ini adalah kode yang berhasil dijalankan
# mencetak langsung ke json yang bisa di baca oleh browser
# return jsonify(tampilkanData.to_dict())
return jsonify(nama=request.form['nama'])
if __name__ == '__main__':
aplikasi.run(host='0.0.0.0',port=8543, debug=True)
</code></pre>
<br>
<h3>file1.html</h3>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="http://1.1.3.3:8543/tampilData" method="POST">
<p>Nama : <input type="text" name="nama"/></p>
<p>Alamat : <input type="text" name="alamat"/></p>
<p><input type="submit" value="submit"></p>
</form>
</body>
</html>
</code></pre>
<br>
<br>
<h2>Latihan 9</h2>
<p>In this exercise, we successfully input data using Flask. Then, we take each data that was filled in the textbox and display it to the jinja2 template. All processes are done by clicking a button.</p>
<br>
<h3>file1.py</h3>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> from jinja2 import Template
from flask import Flask,render_template,request,json,jsonify
aplikasi = Flask(__name__)
@aplikasi.route('/')
def formUtama():
return render_template("halaman1.html")
@aplikasi.route('/tampilData', methods = ['POST'])
def tampilkanData():
if request.method == 'POST':
text1 = request.form.get('text1')
text2 = request.form.get('text2')
return render_template("halaman2.html", tampilText1=text1, tampilText2=text2)
# source code nya ini sudah bagus untuk menerima inputan dari form
if __name__ == '__main__':
aplikasi.run(host='0.0.0.0',port=8543,debug=True)
</code></pre>
<br>
<h3>halaman1.html</h3>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
<style>
input[type=text], select{
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1 px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type=submit]{
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049
}
div {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
</style>
</head>
<body>
<h3>Formulir Data Printer</h3>
<div>
<form action="http://1.1.3.6:8543/tampilData" method="POST" id="formPrinter" name="formPrinter">
<label for="text1">Text 1</label>
<input type="text" id="text1" name="text1" placeholder="Isikan kata 1">
<input type="text" id="text2" name="text2" placeholder="Isikan kata 2">
<input type="submit" Value="submit">
</form>
</div>
</body>
</html>
</code></pre>
<br>
<h3>halaman2.html</h3>
<pre style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;;background-image:URL(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSEzZUdbNWF3ncljp5Fp1BM6tahEN-3K3ELvPenGB-enLLUYNsshy76rwz7shLuPfcE3Amte7bMNTQ6nAplblaeKIldI1HUifamT-QWrSezz-9M_o10hpopOdaadzK9OZcO1SbCZdvQpp1/s320/codebg.gif);padding:0px;color:#000000;text-align:left;line-height:20px;"><code style="color:#000000;word-wrap:normal;"> <!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>{{ tampilText1 }}</p>
<p>{{ tampilText2 }}</p>
<!--- source code nya ini sudah bagus untuk menampilkan hasil inputan dari form -->
</body>
</html>
</code></pre>
Unknownnoreply@blogger.com0Balikpapan, Kota Balikpapan, Kalimantan Timur, Indonesia-1.2379274 116.8528526-29.548161236178846 81.6966026 27.072306436178845 152.0091026