Need help adding additional functionality to the program I have below, I tried to add some of the functionality in my program but I am lost on what I need to do. I have included:
- the assignment
- the version of app.py file where I added some functionality
- the original version of app.py file
- the html files I have not edited yet
This is the outline of the assignment of I am working on:
This exercise uses your programming environment to enhance the Web site you created last week with additional functionality to include images, tables and a Form using Python flask. Specifically, you will add two (2) additional routes allowing a user to register and login to a web site. Additional security considerations include other routes (beyond the register route) will not be accessible until a successful login has occurred.
In addition to the requirements list above the following functionality should be found within your web site on one or more web pages.
Add at least 4 different images. The images should be local in your environment. For example, they should be saved in your environment and referenced similar to this syntax:<img src=”image.gif”>
- A Table with at least 4 rows and 3 columns.
- A user registration form
- A user login form
- A password complexity should be enforced to include at least 12 characters in length, and include at least 1 uppercase character, 1 lowercase character, 1 number and 1 special character.
The content and topic of the new images, and tables are up to you. How much is required for the user registration is up to you as well. However, the registration and associated login should contain at least a login name and password.
Hints:
1. Start early. This will take you longer than you think.
2. Test all aspects of the forms from input to output on your environment.
3. Use comments to document your code
4. Test with many combinations.
5. Use pylint to verify the code style – the goal is a 10!
Here is my code I with some of the enhancements:
app.py file:
# Let's import date function to display the date today in our website
from datetime import date
# Import required libraries for flask to work
import Scaffold as Scaffold
from flask import Flask, render_template
# Initialize flask, store the flask instance in the app variable
import os
import sys
import weakref
from datetime import timedelta
from itertools import chain
from werkzeug.datastructures import ImmutableDict
from werkzeug.routing import Rule, Map
app = Flask(__name__)
def _make_timedelta(value):
if value is None or isinstance(value, timedelta):
return value
return timedelta(seconds=value)
class Flask(Scaffold):
jinja_options = {}
default_config = ImmutableDict(
{
"ENV": None,
"DEBUG": None,
"TESTING": False,
"PROPAGATE_EXCEPTIONS": None,
"PRESERVE_CONTEXT_ON_EXCEPTION": None,
"SECRET_KEY": None,
"PERMANENT_SESSION_LIFETIME": timedelta(days=31),
"USE_X_SENDFILE": False,
"SERVER_NAME": None,
"APPLICATION_ROOT": "/",
"SESSION_COOKIE_NAME": "session",
"SESSION_COOKIE_DOMAIN": None,
"SESSION_COOKIE_PATH": None,
"SESSION_COOKIE_HTTPONLY": True,
"SESSION_COOKIE_SECURE": False,
"SESSION_COOKIE_SAMESITE": None,
"SESSION_REFRESH_EACH_REQUEST": True,
"MAX_CONTENT_LENGTH": None,
"SEND_FILE_MAX_AGE_DEFAULT": None,
"TRAP_BAD_REQUEST_ERRORS": None,
"TRAP_HTTP_EXCEPTIONS": False,
"EXPLAIN_TEMPLATE_LOADING": False,
"PREFERRED_URL_SCHEME": "http",
"JSON_AS_ASCII": True,
"JSON_SORT_KEYS": True,
"JSONIFY_PRETTYPRINT_REGULAR": False,
"JSONIFY_MIMETYPE": "application/json",
"TEMPLATES_AUTO_RELOAD": None,
"MAX_COOKIE_SIZE": 4093,
}
)
#: The rule object to use for URL rules created. This is used by
#: :meth:`add_url_rule`. Defaults to :class:`werkzeug.routing.Rule`.
#:
#: .. versionadded:: 0.7
url_rule_class = Rule
#: The map object to use for storing the URL rules and routing
#: configuration parameters. Defaults to :class:`werkzeug.routing.Map`.
#:
#: .. versionadded:: 1.1.0
url_map_class = Map
#: the test client that is used with when `test_client` is used.
#:
#: .. versionadded:: 0.7
test_client_class = None
#: The :class:`~click.testing.CliRunner` subclass, by default
#: :class:`~flask.testing.FlaskCliRunner` that is used by
#: :meth:`test_cli_runner`. Its ``__init__`` method should take a
#: Flask app object as the first argument.
#:
#: .. versionadded:: 1.0
test_cli_runner_class = None
# This is how you declare route in flask
# this route will point to http://127.0.0.1:5000/
@app.route('/')
def home():
"""Let's store the date today to be display in the page"""
date_today = date.today()
# render_template displays html page
# We can indicate what page to show, and pass variables for our html page to use
return render_template('index.html', today=date_today)
@app.route('/contact_us')
def contact_us():
"""this route will point to http://127.0.0.1:5000/contact_us"""
return render_template('contact_us.html')
@app.route('/about_us')
def about_me():
"""this route will point to http://127.0.0.1:5000/about_us"""
return render_template('about_us.html')
# this file will only run only if you directly called this python file
# e.g python app.py
# it also says that this is the starting point of your program
if __name__ == '__main__':
app.run()
Original app.py before I added any of the enhancements:
app.py file:
# Let's import date function to display the date today in our website
from datetime import date
# Import required libraries for flask to work
from flask import Flask, render_template
# Initialize flask, store the flask instance in the app variable
app = Flask(__name__)
# This is how you declare route in flask
# this route will point to http://127.0.0.1:5000/
@app.route('/')
def home():
"""Let's store the date today to be display in the page"""
date_today = date.today()
# render_template displays html page
# We can indicate what page to show, and pass variables for our html page to use
return render_template('index.html', today=date_today)
@app.route('/contact_us')
def contact_us():
"""this route will point to http://127.0.0.1:5000/contact_us"""
return render_template('contact_us.html')
@app.route('/about_us')
def about_me():
"""this route will point to http://127.0.0.1:5000/about_us"""
return render_template('about_us.html')
# this file will only run only if you directly called this python file
# e.g python app.py
# it also says that this is the starting point of your program
if __name__ == '__main__':
app.run()
Index.html file:
<!DOCTYPE html>
<html>
<head>
<title> Python Project 6!</title>
<!-- We can also use external style sheet which is stored in static/css-->
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
</head>
<body>
<!-- Here is an example of a comment tag,
this is useful if you want to describe section, add notes,
or even you can disable a code that you don't want to delete
like this <b> Disable this code </b>
-->
<!-- you can use h1, h2, h3, h4 , h5 and h6 to display
header in html. h1 is the largest while h6 is the smallest-->
<h1> Finding Ice cream for you! </h1>
<!-- hr stands for horizontal rule. It's a best practice
to add forward slash for single tags like <hr> and <br>
-->
<hr/>
<p> Menu </p>
<!-- We can also insert inline style-->
<div style="width: 100%; height: auto; background-color: #CCC;">
<ul class="menu">
<li><a href="/"> Home</a></li>
<li><a href="/contact_us" > Contact Us </a></li>
<li><a href="/about_us"> About Us</a></li>
</ul>
</div>
<!-- br stands for break. It add new line-->
<br/>
<h4> Here's our best Ice Cream to eat! </h4>
<!-- ol stands for Ordered list.
each item in the list is enclosed in <li> tag-->
<ol>
<li> Vanilla </li>
<li> Chocolate </li>
<li> Cookies & Cream </li>
</ol>
<p>
Special discount will be given this week!<br/>
Don't eat ice cream to fast.
</p>
<!-- Display the date today.
We are displaying value of the variable 'today'
that we got from flask-->
<p> Date today is: {{ today }}</p>
<!-- unordered list, similar to ol but without numbering-->
<ul>
<li><a href="https://mcbroken.com/" target="_blank" > Find McDonald Ice cream</a></li>
<li><a href="https://www.haagendazs.us/recipes" target="_blank"> Ice cream recipes</a></li>
<li><a href="https://www.benjerry.com/" target="_blank"> Ben & Jerry </a></li>
</ul>
</body>
contact_us.html file:
<!DOCTYPE html>
<html>
<head>
<title> Python Project 6!</title>
</head>
<body>
<!-- Here is an example of a comment tag,
this is useful if you want to describe section, add notes,
or even you can disable a code that you don't want to delete
like this <b> Disable this code </b>
-->
<!-- you can use h1, h2, h3, h4 , h5 and h6 to display
header in html. h1 is the largest while h6 is the smallest-->
<h1> Contact us </h1>
<h4> No info here! </h4>
<!-- hr stands for horizontal rule. It's a best practice
to add forward slash for single tags like <hr> and <br>
-->
<hr/>
<p> Menu </p>
<div style="width: 100%; height: auto; background-color: #CCC;">
<ul style="list-style-type:none;">
<li><a href="/"> Home</a></li>
<li><a href="/contact_us"> Contact Us </a></li>
<li><a href="/about_us"> About Us</a></li>
</ul>
</div>
<!-- br stands for break. It add new line-->
<br/>
</body>
</html>
about_us.html file:
<!DOCTYPE html>
<html>
<head>
<title> Python Project 6</title>
</head>
<body>
<!-- Here is an example of a comment tag,
this is useful if you want to describe section, add notes,
or even you can disable a code that you don't want to delete
like this <b> Disable this code </b>
-->
<!-- you can use h1, h2, h3, h4 , h5 and h6 to display
header in html. h1 is the largest while h6 is the smallest-->
<h1> About us </h1>
<h4> Ice Cream ! </h4>
<!-- hr stands for horizontal rule. It's a best practice
to add forward slash for single tags like <hr> and <br>
-->
<hr/>
<p> Menu </p>
<div style="width: 100%; height: auto; background-color: #CCC;">
<ul style="list-style-type:none;">
<li><a href="/"> Home</a></li>
<li><a href="/contact_us"> Contact Us </a></li>
<li><a href="/about_us"> About Us</a></li>
</ul>
</div>
<!-- br stands for break. It add new line-->
<br/>
</body>
</html>
style.css file:
body {
margin: 0;
padding: 0;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.menu {
list-style-type:none;
}