Skip to content

Commit

Permalink
Add flask
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhthtran committed Sep 20, 2024
1 parent f4b83e1 commit df74dde
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 0 deletions.
Binary file added FlaskExercise/.DS_Store
Binary file not shown.
12 changes: 12 additions & 0 deletions FlaskExercise/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import logging
from flask import Flask

app = Flask(__name__)
wsgi_app = app.wsgi_app
# TODO: Set the app's logger level to "warning"
# and any other necessary changes
app.logger.setLevel(logging.WARNING)
streamHandler = logging.StreamHandler()
streamHandler.setLevel(logging.WARNING)
app.logger.addHandler(streamHandler)
import FlaskExercise.views
Binary file added FlaskExercise/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added FlaskExercise/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added FlaskExercise/__pycache__/views.cpython-310.pyc
Binary file not shown.
Binary file added FlaskExercise/static/.DS_Store
Binary file not shown.
26 changes: 26 additions & 0 deletions FlaskExercise/static/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
html {
font-family: OpenSans, sans-serif;
color: #fff;
}
body {
background: #02B3E4;
}
.container {
display:grid;
grid-gap: 20px;
grid-template-areas:
"hd hd hd"
"main main main"
"ft ft ft";
text-align: center;
}
.header {
grid-area: hd;
font-size: 32px;
}
.footer {
grid-area: ft;
}
.content {
grid-area: main;
}
Binary file added FlaskExercise/templates/.DS_Store
Binary file not shown.
30 changes: 30 additions & 0 deletions FlaskExercise/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Monitoring & Logging</title>
<meta
content="width=device-width, initial-scale=1, maximum-scale=1"
name="viewport"
/>
<link rel="stylesheet" type="text/css" href="../static/main.css"/>
</head>

<body>
<div class = "container">
<div class="header box">Logging Center</div>
<div class="content box">
{% if log %}
<p>{{ log }}</p>
{% endif %}
<form action="/">
<input type="submit" name="log_button" value="info">
<input type="submit" name="log_button" value="warning">
<input type="submit" name="log_button" value="error">
<input type="submit" name="log_button" value="critical">
</form>
</div>
<div class="footer box">Copyright 2020 Udacious Student</div>
</div>
</body>
</html>
22 changes: 22 additions & 0 deletions FlaskExercise/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from flask import flash, render_template, redirect, request
from FlaskExercise import app


@app.route('/')
def home():
log = request.values.get('log_button')
# TODO: Appropriately log the different button presses
# with the appropriate log level.
if log:
if log == 'info':
app.logger.info('No issue.')
elif log == 'warning':
app.logger.warning('Warning occurred.')
elif log == 'error':
app.logger.error('Error occurred.')
elif log == 'critical':
app.logger.critical('Critical error occurred.') # noqa: E501
return render_template(
'index.html',
log=log
)

0 comments on commit df74dde

Please sign in to comment.