Question: main.py from flask import Flask from studentDB import StudentDB from flask import render_template app = Flask('app') # Use this to get access to student data

 main.py from flask import Flask from studentDB import StudentDB from flaskimport render_template app = Flask('app') # Use this to get access to

main.py

from flask import Flask from studentDB import StudentDB

from flask import render_template app = Flask('app')

# Use this to get access to student data studentsDB = StudentDB(10)

# you may need to add more routes @app.route('/student/') def student(id): for usr in studentsDB: if (usr == id): return render_template("student.html", title=studentsDB[usr]["name"], info= studentsDB.get_student(usr)) return render_template("error.html", msg="Student not found");

@app.route('/') def index(): # TODO: follow instructions print(studentsDB.get_students()) return render_template("index.html", students = studentsDB.get_students())

@app.route('/author') def author(): return "YOUR NAME HERE"

app.run(host='0.0.0.0', port=8080)

index.html

Student Roster

Student Roster

    {% for student in students: %}
  • {{ student['name'] }}
  • {% endfor %}

student.html

{{title}}

{% for i in info: %}

{{i}} : {{info[i]}}

{% endfor %}

studentDB.py

import random # part of Python import names # from https://pypi.org/projectames/

# DO NOT MODIFY THIS FILE!

class StudentDB: def __init__(self, num_students): """ Create num_students random students and store them into the students list. We use the random and names libraries to fill in the random data. """ random.seed(12345) self.students = [] for s in range(num_students): id = f"G{int(random.uniform(1000,9999))}" first = names.get_first_name() last = names.get_last_name() self.students.append({ "name": first + " " + last, "id": id, "email": first[0] + last + "@someuni.edu", "engagement": [int(random.uniform(0,3)) for x in range(10)] })

def get_students(self): """ Get a list of all students. Each student is stored as a dictionary with keys for id, name, email, and a list of engagement point values. """ return self.students

def get_student(self, id): """ Return a dictionary representing a specific student by their ID number """ for s in self.students: if s["id"] == id: return s return None

Requirements: Your website should contain three types of pages: 1. Home page (/): Should display a list of students in the class by name. Clicking on a student's name should take them to a student data page 2. Student Data page: This should display a report about a specific student including: Full name ID number Email address Engagement points by week - each student has a list representing how many engagement points they have earned per week over the course of 10 weeks. You should display each entry and color code it as follows: green if they received 2 points, orange for 1 point, or red for 0 points Total engagement points - display the total points they have earned over all ten weeks 3. Author page ( (author): This page should simply return your full name to help with grading. Your site must use Python Flask Templates to display the top two types of pages. You must use CSS to change the default styling, and you should use CSS classes to change the color of engagement point entries. Let your creativity guide you. = Accessing Student Data To get access to the student data, you must use the provided StudentDB class -- this will mimic interacting with a database. The StudentDB class provides an API to get information about students: def get_students (self): II III Get a List of all students. Each student is stored as a dictionary with keys for id, name, email, and a list of engagement point values. IIIIII def get_student(self, id): 11 11 11 Return a dictionary representing a specific student by their ID number 11 II 11 The first function returns a List with all students in the class, while the second will return a specific student based on their ID number. If you aren't familiar with Python class syntax such as the self keyword, check Full Speed Python's Chapter 8. Here is sample usage: from studentDB import StudentDB = # Create a fake DB with 10 students studentsDB = Student DB

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!