Skip to content
Snippets Groups Projects
Commit ffd0c95a authored by Michael Kyriakou's avatar Michael Kyriakou
Browse files

Added "surname" to index form.

parent 43ee2a76
No related branches found
No related tags found
No related merge requests found
......@@ -37,14 +37,20 @@ If you navigate to `http://localhost:5000`, you will see the response created by
You will also notice the lines `Environment: production` and `Debug mode: off` when the Flask application starts in the console. To enable debug mode, you must set the environment variable `ENV` to `dev`, ie: `export ENV=dev` (see `config/config.py` for more details on different environments).
## Tutorial 1: Adding a new route
# Flask Routes
A "route manager" in Flask is called a "Blueprint", all blueprints need to be "registered" in `app.py`, otherwise they will not be accessible. A "router manager" has the role of handling requests from all routes that start with the provided "url_prefix".
## Tutorial: Adding a new blueprint
TODO
## Tutorial: Adding a new route
TODO
Example: `items = Blueprint("items", __name__, url_prefix="/inventory/items")`
## Tutorial 2: Adding database interaction
## Tutorial: Adding database interaction
TODO
## Tutorial 3: Configuring a test environment
# Flask Migrations and Databases
......
......@@ -29,11 +29,13 @@ def persons():
except Exception as e:
return f"App database error: {e}"
else:
firstname = request.form.get('firstname')
age = request.form.get('age')
req_form = request.form
firstname = req_form.get('firstname')
age = req_form.get('age')
surname = req_form.get("surname")
try:
Person.add(firstname, int(age))
Person.add(firstname, surname, int(age))
return redirect(url_for2('.persons'))
except Exception as e:
return f"Could not add entity: {e}"
......@@ -21,8 +21,8 @@ class Person(db.Model):
phone_numbers = db.relationship('PhoneNumber', cascade='all,delete', backref=__tablename__)
@classmethod
def add(cls, firstname, age):
db.session.add(Person(firstname=firstname, age=int(age)))
def add(cls, firstname, surname, age):
db.session.add(Person(firstname=firstname, surname=surname, age=int(age)))
db.session.commit()
@classmethod
......
......@@ -26,6 +26,9 @@
Firstname:<br>
<input type="text" name="firstname">
<br>
Surname:<br>
<input type="text" name="surname">
<br>
Age:<br>
<input type="number" name="age">
<br>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment