Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please i need help with this .py JSON code to connect and insert into database to allow a clerk to show a book, edit book,

Please i need help with this .py JSON code to connect and insert into database to allow a clerk to show a book, edit book, delete book, and create a new book in database. Thanks in advance

The goal of this is to create a Data-Driven Web Application using Flask to perform CRUD operations: Create, Read, Update and Delete.

Initially, you are give a list of books. Each book's data is represented as a dictionary.

books = [{'title': 'Software Engineering', 'id': '1'}, {'title': 'Algorithm Design', 'id':'2'}, {'title': 'Python', 'id':'3'}]

The webpages of the assignment are as follows:

1. showBook.html

When "assignment2.py" is executed, the "showBook.html" must be the first webpage to be rendered by the browser.

This page must list all available books. For each book, it must provide the user with the options to either edit the book title or delete the book's data from the dictionary.

2. editBook.html

The user reaches this page after choosing to edit the title of one of the books in the page "showBook.html".

If the user enters a string in the displayed textbox, this string must replace the book's title in the corresponding dictionary.

3. deleteBook.html

The user reaches this page after choosing the option delete in the page "showBook.html".

If the user hits the delete button, the corresponding dictionary of that book, i.e., the title and the id, will be deleted from the list of the available books.

4. newBook.html

The user reaches to this page when typing in the following URL into the browser.

http://127.0.0.1:5000/book/new/Links to an external site.

If the user enters a string in the displayed textbox, a new dictionary will be added to the list of available books. The Dictionary will have the entered string and assigns it the next available id (i.e., the first found empty slot).

This is the initial code:

from flask import Flask, render_template, request, redirect, url_for, jsonify import random app = Flask(__name__)

books = [{'title': 'Software Engineering', 'id': '1'}, \ {'title': 'Algorithm Design', 'id':'2'}, \ {'title': 'Python', 'id':'3'}]

@app.route('/book/JSON') def bookJSON(): #

@app.route('/') @app.route('/book/') def showBook(): # @app.route('/book/new/', methods=['GET', 'POST']) def newBook(): #

@app.route('/book//edit/', methods=['GET','POST']) def editBook(book_id): # @app.route('/book//delete/', methods = ['GET', 'POST']) def deleteBook(book_id): #

if __name__ == '__main__': app.debug = True app.run(host = '0.0.0.0', port = 5000)

Please help!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

0121016250, 978-0121016258

More Books

Students also viewed these Databases questions