App flask
This commit is contained in:
2
flask/.env
Normal file
2
flask/.env
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
source env/bin/activate
|
||||||
|
export APP_SETTINGS="config.DevelopmentConfig"
|
||||||
6
flask/README.md
Normal file
6
flask/README.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
https://realpython.com/flask-by-example-part-1-project-setup/
|
||||||
|
|
||||||
|
|
||||||
|
https://realpython.com/introduction-to-flask-part-1-setting-up-a-static-site/
|
||||||
|
https://realpython.com/introduction-to-flask-part-2-creating-a-login-page/
|
||||||
37
flask/app.py
Normal file
37
flask/app.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import os
|
||||||
|
from flask import Flask, render_template, redirect, url_for, request
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
app.config.from_object(os.environ['APP_SETTINGS'])
|
||||||
|
print(os.environ['APP_SETTINGS'])
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def home():
|
||||||
|
return "Hello World!"
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/<name>')
|
||||||
|
def hello_name(name):
|
||||||
|
return "Hello {}!".format(name)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/welcome')
|
||||||
|
def welcome():
|
||||||
|
return render_template('welcome.html') # render a template
|
||||||
|
|
||||||
|
|
||||||
|
# Route for handling the login page logic
|
||||||
|
@app.route('/login', methods=['GET', 'POST'])
|
||||||
|
def login():
|
||||||
|
error = None
|
||||||
|
if request.method == 'POST':
|
||||||
|
if request.form['username'] != 'admin' or request.form['password'] != 'admin':
|
||||||
|
error = 'Invalid Credentials. Please try again.'
|
||||||
|
else:
|
||||||
|
return redirect(url_for('home'))
|
||||||
|
return render_template('login.html', error=error)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app.run()
|
||||||
27
flask/config.py
Normal file
27
flask/config.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import os
|
||||||
|
basedir = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
||||||
|
class Config(object):
|
||||||
|
DEBUG = False
|
||||||
|
TESTING = False
|
||||||
|
CSRF_ENABLED = True
|
||||||
|
SECRET_KEY = 'this-really-needs-to-be-changed'
|
||||||
|
|
||||||
|
|
||||||
|
class ProductionConfig(Config):
|
||||||
|
DEBUG = False
|
||||||
|
|
||||||
|
|
||||||
|
class StagingConfig(Config):
|
||||||
|
DEVELOPMENT = True
|
||||||
|
DEBUG = True
|
||||||
|
|
||||||
|
|
||||||
|
class DevelopmentConfig(Config):
|
||||||
|
DEVELOPMENT = True
|
||||||
|
DEBUG = True
|
||||||
|
|
||||||
|
|
||||||
|
class TestingConfig(Config):
|
||||||
|
TESTING = True
|
||||||
5
flask/requierements.txt
Normal file
5
flask/requierements.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
Flask
|
||||||
|
itsdangerous
|
||||||
|
Jinja2
|
||||||
|
requests
|
||||||
|
Werkzeug
|
||||||
7
flask/static/bootstrap.min.css
vendored
Normal file
7
flask/static/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
7
flask/static/bootstrap.min.js
vendored
Normal file
7
flask/static/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
23
flask/templates/login.html
Normal file
23
flask/templates/login.html
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Flask Intro - login page</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link href="static/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Please login</h1>
|
||||||
|
<br>
|
||||||
|
<form action="" method="post">
|
||||||
|
<input type="text" placeholder="Username" name="username" value="{{
|
||||||
|
request.form.username }}">
|
||||||
|
<input type="password" placeholder="Password" name="password" value="{{
|
||||||
|
request.form.password }}">
|
||||||
|
<input class="btn btn-default" type="submit" value="Login">
|
||||||
|
</form>
|
||||||
|
{% if error %}
|
||||||
|
<p class="error"><strong>Error:</strong> {{ error }}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
14
flask/templates/welcome.html
Normal file
14
flask/templates/welcome.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Flask Intro</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Welcome to Flask!</h2>
|
||||||
|
<br>
|
||||||
|
<p>Click <a href="/">here</a> to go home.</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user