added login form from tutorial

This commit is contained in:
2019-08-19 22:19:05 -05:00
parent b0b1d58939
commit b19a44a6e9
6 changed files with 63 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
from flask import Flask
from config import Config
app = Flask(__name__)
app.config.from_object(Config)
from app import routes

4
app/config.py Normal file
View File

@@ -0,0 +1,4 @@
import os
class Config(object):
SECRET_KEY = os.environ.get('SECRET_KEY') or os.urandom(16)

9
app/forms.py Normal file
View File

@@ -0,0 +1,9 @@
from flask_wtf import FlaskForm
from wtforms import StringField, PassworkField, BooleanField, SubmitField
from wtforms.validators import DataRequired
class LoginForm(FlaskForm):
username = StringField('Username', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()])
remember_me = BooleanField('Remember Me')
submit = SubmitField('Sign In')

View File

@@ -1,11 +1,27 @@
from flask import render_template
from app import app
from app.forms import LoginForm
from flask import send_file
from flask import send_from_directory
@app.route('/')
@app.route('/index')
def index():
user = {'username': 'Miguel'}
posts = [
{
'author': {'username': 'John'},
'body': 'Beautiful day in Portland!'
},
{
'author': {'username': 'Susan'},
'body': 'The Avengers movie was so cool!'
}
]
return render_template('index.html', title='Home', user=user, posts=posts)
@app.route('/status')
def getstatus():
device = {'name': 'find how to get name later'}
status = {'temperature': float(open('/sys/class/thermal/thermal_zone0/temp').read()) / 1000}
return render_template('status.html', device=device, status=status)

14
app/templates/base.html Normal file
View File

@@ -0,0 +1,14 @@
<html>
<head>
{% if title %}
<title>{{ title }} - Microblog</title>
{% else %}
<title>Welcome to Microblog</title>
{% endif %}
</head>
<body>
<div>Microblog: <a href="/index">Home</a></div>
<hr>
{% block content %}{% endblock %}
</body>
</html>

18
app/templates/login.html Normal file
View File

@@ -0,0 +1,18 @@
{% extends "base.html" %}
{% block content %}
<h1>Sign In</h1>
<form action="" method="post" novalidate>
{{ form.hidden_tag() }}
<p>
{{ form.username.label }}<br>
{{ form.username(size=32) }}
</p>
<p>
{{ form.password.label }}<br>
{{ form.password(size=32) }}
</p>
<p>{{ form.remember_me() }} {{ from.remember_me.label }}</p>
<p>{{ form.submit() }} </p>
</form>
{% endblock %}