init
This commit is contained in:
16
flaskapp/__init__.py
Normal file
16
flaskapp/__init__.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from flask import Flask
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
import os # if you wanna have db credenitalas in os.environ
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# SQLAlchemy setup
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///flaskapp.db'
|
||||
|
||||
#MySql setup
|
||||
#app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://user:pass@localhost/dbname'
|
||||
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
from flaskapp import routes
|
0
flaskapp/functions.py
Normal file
0
flaskapp/functions.py
Normal file
7
flaskapp/models.py
Normal file
7
flaskapp/models.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from flaskapp import db
|
||||
|
||||
class Table(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
variable1 = db.Column(db.Integer, nullable=False)
|
||||
variable2 = db.Column(db.Integer, nullable=False)
|
||||
|
34
flaskapp/routes.py
Normal file
34
flaskapp/routes.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from flask import render_template, request, redirect
|
||||
from flaskapp import app, db
|
||||
from flaskapp.functions import *
|
||||
from flaskapp.models import *
|
||||
|
||||
@app.route('/', methods=['GET'])
|
||||
def index():
|
||||
if request.method == 'GET':
|
||||
localvariable1 = "Placeholder1"
|
||||
localvariable1 = "Placeholder2"
|
||||
try:
|
||||
return render_template('index.html', pagevariable1 = localvariable1, pagevariable2 = localvariable2 )
|
||||
except:
|
||||
return 'Error retriving page'
|
||||
else:
|
||||
return 'HTTP request method not recogniezed'
|
||||
|
||||
@app.route('/submit', methods=['POST', 'GET'])
|
||||
def submit():
|
||||
if request.method == 'GET':
|
||||
return render_template('submit.html')
|
||||
elif request.method == 'POST':
|
||||
userinput1 = request.form['forminput1']
|
||||
userinput2 = request.form['forminput2']
|
||||
sqlrow = Table(variable1 = int(userinput1), variable2 = int(userinput2))
|
||||
try:
|
||||
db.session.add(sqlrow)
|
||||
db.session.commit()
|
||||
return 'Row added'
|
||||
except:
|
||||
return 'Adding row to table failed'
|
||||
|
||||
else:
|
||||
return 'HTTP request method not recogniezed'
|
48
flaskapp/static/style.css
Normal file
48
flaskapp/static/style.css
Normal file
@@ -0,0 +1,48 @@
|
||||
:root {
|
||||
--border-radus: 1rem;
|
||||
--background: #000000;
|
||||
--header-background: #FFFFFF;
|
||||
--header-height: 3rem;
|
||||
--input-bar-height: 3rem;
|
||||
}
|
||||
|
||||
body{
|
||||
background: var(--background);
|
||||
font-family: sans-serif;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-self: flex-start;
|
||||
gap: 1rem;
|
||||
margin: 0 auto;
|
||||
height: calc(100vh - var(--header-height) - var(--input-bar-height));
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
header {
|
||||
background-color: var(--header-background);
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
padding: 0 1rem;
|
||||
gap: 1rem;
|
||||
font-weight: bold;
|
||||
height: var(--header-height);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
footer {
|
||||
width: 100vw;
|
||||
height: var(--input-bar-height);
|
||||
background-color: var(--background);
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
padding: 0 1rem;
|
||||
box-sizing: border-box;
|
||||
gap: 1rem;
|
||||
}
|
21
flaskapp/templates/index.html
Normal file
21
flaskapp/templates/index.html
Normal file
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Index</title>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
</header>
|
||||
<main>
|
||||
<section>
|
||||
<p> {{ pagevariable1 }} <p>
|
||||
<p> {{ pagevariable2 }} <p>
|
||||
</section>
|
||||
</main>
|
||||
<footer>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
20
flaskapp/templates/submit.html
Normal file
20
flaskapp/templates/submit.html
Normal file
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Submit</title>
|
||||
<link rel="stylesheet" href="/static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<form action="/submit" method="POST">
|
||||
<label for="forminput1">forminput1</label>
|
||||
<input type="text" name="forminput1" id="forminput1" required>
|
||||
<label for="forminput2">forminput2</label>
|
||||
<input type="text" name="forminput2" id="forminput2" required>
|
||||
<button> Submit </button>
|
||||
</form>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user