Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask redo, Unit Converter #347

Open
wants to merge 1 commit into
base: Rafael-DJANGO-BLOG
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Code/Rafael/Flask_Redo/Flask_Redo_unit_converter/Flask_Redo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -Rafael Medina -Class Raven -Flask Unit Converter





meters_convert = {
'ft': 0.3048,
'm': 1,
'km': 1000,
'mi': 1609.34
}




i = 0


while i == 0:


q1 = int(input('What is the distance in meters? '))

q2 = (input('what are the units?; ft, m, km, mi: '))

total = q1 * meters_convert[q2]

print(total, 'meters')

#else:
#print('Try again, select either miles: "mi", meters: "m", kilometers: "km" or feet: "ft" after entering a distance')
break
46 changes: 46 additions & 0 deletions Code/Rafael/Flask_Redo/Flask_Redo_unit_converter/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from flask import Flask, render_template, url_for


app = Flask(__name__)

# render to the page specified


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

app.run(debug=True)


@app.route('/', methods=['POST'])
def answer():

meters_convert = {
'ft': 0.3048,
'm': 1,
'km': 1000,
'mi': 1609.34
}

i = 0

while i == 0:

q1 = int(input('What is the distance in meters? '))

q2 = (input('what are the units?; ft, m, km, mi: '))

total = q1 * meters_convert[q2]

print(total, 'meters')

#else:
#print('Try again, select either miles: "mi", meters: "m", kilometers: "km" or feet: "ft" after entering a distance')
break

return render_template('index.html', total=total)

#runs Flask automatically at start
if __name__ == '__main__':
app.run()
20 changes: 20 additions & 0 deletions Code/Rafael/Flask_Redo/Flask_Redo_unit_converter/static/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
h1 {
text-align: center;
padding-top: 150px;
}


#form{
text-align: center;
}

.input-1{
min-width: 200px;

}

.input-2{
min-width: 100px;

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,">
<meta http-equiv="X-UA-Compatible" content="IE=">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="index.css") }}">
<title>Flask Redo Unit Converter</title>
</head>



<body>
<div class=""> Meters Converted</div>
<h3 class="answer">{{ total }}</h3>

</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport">
<meta http-equiv="X-UA-Compatible" content="IE=">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename="index.css") }}">
<title>Flask Redo Unit Converter</title>
</head>



<body>

<div>
<h1> Unit Converter in Meters {{ name }}</h1>
</div>

<div>

<form action="{{ url_for('index') }}" method="POST" id="form">
<input type="text" name="" class="input-1" placeholder="your distance in meters here.. "/>
<br>
<br>
<br>
<br>
<input type="text" name="" class="input-2" placeholder="'ft', 'm', 'km', 'mi': "/>
<button type="submit" name="" >Submit</button>
</div>


</body>

</html>