SQL databases are used to store and manage the data used by web apps. In this...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
SQL databases are used to store and manage the data used by web apps. In this assignment, you will create a simple web app using the Flask server in Python and connect it to our course database, and then to your local database server, using an object relational mapper (ORM). You will need to refer to online documentation, Web searching, and sources such as Stack Overflow to do research for this assignment. If you get stuck, refer to a tutorial on developing a Flask app. There is also some sample code available (see the Files section on Insendi). If you are stuck, you can run the sample code, then check for differences between your code and the working sample app (using the bridge method - see the document on this method). If you are still stuck after trying these approaches, please post on EdStem with a detailed description of your issue and the error you encountered, including code and/or screenshots. Choice of database In this assignment, you will build a web app which connects to a database. For the questions which read from the database, you may connect to either your local database server or the course server, whichever is more convenient. If you experience connectivity problems with the course server, you can use your local database server. For the questions which write to the database, you must use your local database server (unless it is impossible for you to connect to the course server) to avoid damage to the course server. (3 marks) Write an introduction to your report, giving context and background to the reader, and explaining what you are going to do in your report. Introduction Question 1 (4 marks) Explain how SQL databases are used alongside websites, web apps and mobile apps to store users' data. Discuss in particular the reason why web servers can be easily horizontally scaled, but database servers cannot. Question 2 (2 marks) Explain the concept of the ORM (object-relational mapper) and how such tools are useful in database programming. Question 3 (2 marks) Give a brief overview of each of the following software tools. Your overview should mention functionality, applications, history, and the meaning of the tool's name. The Flask server (Python library) The psycopg2 database connector (Python library) The SQLAlchemy ORM (Python library) The overview should be written up as a passage of text rather than using tables or bullet lists. Question 4 (1 mark) Check whether Flask is installed. If it is not, install Flask using pip. If you get stuck, check some examples or try conda instead of pip. Explain what you did in this step in your own words, and include a screenshot. Question 5 (1 mark) Create a folder called server. In this folder, save the following as a Python file called app.py: from flask import Flask app = Flask (__name__) @app.route('/') def hello world(): return 'Hello, World!' Then run this file using the flask run command on the command line. You may need to set an environment variable using set or export to get this to work. The Flask server is now serving a web page. Visit this page in your browser. Explain what you did in this step in your own words, and include a screenshot. Question 6 (2 marks) While developing, when we make a change to the code, we want to easily see it in the browser when the page is refreshed. With the Flask server still running, change 'Hello, World!' to something else. Refresh the web page. Is the new value shown? Configure your Flask environment to automatically reload the code when you change it. (Hint: look up the FLASK_DEBUG environment variable). Explain what you did in this step in your own words, and include a screenshot. Question 7 (2 marks) To show web pages, Flask uses templates. A template is a file containing hypertext markup language (HTML) code which will eventually be rendered as a web page. Research how to add a template to your Flask app, then add a simple HTML page. Explain what you did in this step in your own words, and include a screenshot. Show also all your code. Question 8 (2 marks) Drawing on tutorials and the Flask sample code made available, use the psycopg2 database connector to display information, from a database table, in your app. Choose one of the database tables in northwind or dvdrental, then use psycopg2 to pull information from that table into a Python data structure. Create a new web page in your app and use a template file to loop over the table rows and display them on the page. Explain what you did in this step in your own words, and include a screenshot of the app running locally. Show also the relevant new code. Question 9 (4 marks) Drawing on tutorials and the Flask sample code made available, add Flask-SQLAlchemy to your app. Add a database model for one of the database tables in northwind or dvdrental (not the movies table or the table you used in the previous question), then (as in the previous question) use a template to create a page listing all the rows in this table. Explain what you did in this step in your own words, and include a screenshot of the app running in the browser. Show also the relevant new code. Question 10 (2 marks) Modify the page you just created so that Flask-SQLAlchemy is also used to display the number of rows in the table (research the .count() function in SQLAlchemy). Explain what you did in this step in your own words, and include a screenshot. Show also the relevant new code. Question 11 (4 marks) Research cascading style sheets (CSS), which are used to control the visual appearance of web pages. Use HTML and CSS to add some basic graphic styling to your page. Consider changing the background colour and font; elements on the page could be styled with colours, spacing, border colours, or other styles of your choosing. You may need to check Flask tutorials to see how to add a style sheet to your web app. Explain what you did in this step in your own words, and include a screenshot. Show also the relevant new code. Question 12 (2 marks) Using either Flask-SQLAlchemy or psycopg2, add a new page to your app which lists all films (at least their ID and name). Explain what you did in this step in your own words, and include a screenshot. Explain precisely what SQL queries are performed each time you load this page. Question 13 (3 marks) Modify the previous page to add a new column which shows the name of one actor from each film (or nothing if no actors are known for that film). Explain what you did in this step in your own words, and include a screenshot. Explain precisely what SQL queries are performed by SQLAlchemy each time you load this page, and discuss the differences from the queries performed for the last question. Question 14 (2 marks) Explain the N+1 query problem and discuss the issues it causes, and methods to deal with it. Question 15 (3 marks) Modify your solution for Question X by implementing a solution to the N+1 query problem. Explain what you did in this step in your own words, and include a screenshot. Question 16 (1 mark) Create a new database on your local Postgres server, then create a new table there with at least three rows (you will need to issue the CREATE DATABASE, CREATE TABLE and at least one INSERT statement). Modify your app so that it connects to this new database. Create a new page in your app which lists all the information in this table. Explain what you did in this step in your own words, and include a screenshot. Question 17 (2 marks) Create a new page in your app which allows you to add information to your new database table. The page will need a form with several fields and a Submit button. Verify that this page works by adding rows and refreshing the page which displays the contents of your new table. Explain what you did in this step in your own words, and include a screenshot of the form and a screenshot showing the newly added rows; show also the new code. (3 marks) Write a conclusion to your report, explaining the work done and how you resolved any challenges you faced along the way. Conclusion SQL databases are used to store and manage the data used by web apps. In this assignment, you will create a simple web app using the Flask server in Python and connect it to our course database, and then to your local database server, using an object relational mapper (ORM). You will need to refer to online documentation, Web searching, and sources such as Stack Overflow to do research for this assignment. If you get stuck, refer to a tutorial on developing a Flask app. There is also some sample code available (see the Files section on Insendi). If you are stuck, you can run the sample code, then check for differences between your code and the working sample app (using the bridge method - see the document on this method). If you are still stuck after trying these approaches, please post on EdStem with a detailed description of your issue and the error you encountered, including code and/or screenshots. Choice of database In this assignment, you will build a web app which connects to a database. For the questions which read from the database, you may connect to either your local database server or the course server, whichever is more convenient. If you experience connectivity problems with the course server, you can use your local database server. For the questions which write to the database, you must use your local database server (unless it is impossible for you to connect to the course server) to avoid damage to the course server. (3 marks) Write an introduction to your report, giving context and background to the reader, and explaining what you are going to do in your report. Introduction Question 1 (4 marks) Explain how SQL databases are used alongside websites, web apps and mobile apps to store users' data. Discuss in particular the reason why web servers can be easily horizontally scaled, but database servers cannot. Question 2 (2 marks) Explain the concept of the ORM (object-relational mapper) and how such tools are useful in database programming. Question 3 (2 marks) Give a brief overview of each of the following software tools. Your overview should mention functionality, applications, history, and the meaning of the tool's name. The Flask server (Python library) The psycopg2 database connector (Python library) The SQLAlchemy ORM (Python library) The overview should be written up as a passage of text rather than using tables or bullet lists. Question 4 (1 mark) Check whether Flask is installed. If it is not, install Flask using pip. If you get stuck, check some examples or try conda instead of pip. Explain what you did in this step in your own words, and include a screenshot. Question 5 (1 mark) Create a folder called server. In this folder, save the following as a Python file called app.py: from flask import Flask app = Flask (__name__) @app.route('/') def hello world(): return 'Hello, World!' Then run this file using the flask run command on the command line. You may need to set an environment variable using set or export to get this to work. The Flask server is now serving a web page. Visit this page in your browser. Explain what you did in this step in your own words, and include a screenshot. Question 6 (2 marks) While developing, when we make a change to the code, we want to easily see it in the browser when the page is refreshed. With the Flask server still running, change 'Hello, World!' to something else. Refresh the web page. Is the new value shown? Configure your Flask environment to automatically reload the code when you change it. (Hint: look up the FLASK_DEBUG environment variable). Explain what you did in this step in your own words, and include a screenshot. Question 7 (2 marks) To show web pages, Flask uses templates. A template is a file containing hypertext markup language (HTML) code which will eventually be rendered as a web page. Research how to add a template to your Flask app, then add a simple HTML page. Explain what you did in this step in your own words, and include a screenshot. Show also all your code. Question 8 (2 marks) Drawing on tutorials and the Flask sample code made available, use the psycopg2 database connector to display information, from a database table, in your app. Choose one of the database tables in northwind or dvdrental, then use psycopg2 to pull information from that table into a Python data structure. Create a new web page in your app and use a template file to loop over the table rows and display them on the page. Explain what you did in this step in your own words, and include a screenshot of the app running locally. Show also the relevant new code. Question 9 (4 marks) Drawing on tutorials and the Flask sample code made available, add Flask-SQLAlchemy to your app. Add a database model for one of the database tables in northwind or dvdrental (not the movies table or the table you used in the previous question), then (as in the previous question) use a template to create a page listing all the rows in this table. Explain what you did in this step in your own words, and include a screenshot of the app running in the browser. Show also the relevant new code. Question 10 (2 marks) Modify the page you just created so that Flask-SQLAlchemy is also used to display the number of rows in the table (research the .count() function in SQLAlchemy). Explain what you did in this step in your own words, and include a screenshot. Show also the relevant new code. Question 11 (4 marks) Research cascading style sheets (CSS), which are used to control the visual appearance of web pages. Use HTML and CSS to add some basic graphic styling to your page. Consider changing the background colour and font; elements on the page could be styled with colours, spacing, border colours, or other styles of your choosing. You may need to check Flask tutorials to see how to add a style sheet to your web app. Explain what you did in this step in your own words, and include a screenshot. Show also the relevant new code. Question 12 (2 marks) Using either Flask-SQLAlchemy or psycopg2, add a new page to your app which lists all films (at least their ID and name). Explain what you did in this step in your own words, and include a screenshot. Explain precisely what SQL queries are performed each time you load this page. Question 13 (3 marks) Modify the previous page to add a new column which shows the name of one actor from each film (or nothing if no actors are known for that film). Explain what you did in this step in your own words, and include a screenshot. Explain precisely what SQL queries are performed by SQLAlchemy each time you load this page, and discuss the differences from the queries performed for the last question. Question 14 (2 marks) Explain the N+1 query problem and discuss the issues it causes, and methods to deal with it. Question 15 (3 marks) Modify your solution for Question X by implementing a solution to the N+1 query problem. Explain what you did in this step in your own words, and include a screenshot. Question 16 (1 mark) Create a new database on your local Postgres server, then create a new table there with at least three rows (you will need to issue the CREATE DATABASE, CREATE TABLE and at least one INSERT statement). Modify your app so that it connects to this new database. Create a new page in your app which lists all the information in this table. Explain what you did in this step in your own words, and include a screenshot. Question 17 (2 marks) Create a new page in your app which allows you to add information to your new database table. The page will need a form with several fields and a Submit button. Verify that this page works by adding rows and refreshing the page which displays the contents of your new table. Explain what you did in this step in your own words, and include a screenshot of the form and a screenshot showing the newly added rows; show also the new code. (3 marks) Write a conclusion to your report, explaining the work done and how you resolved any challenges you faced along the way. Conclusion
Expert Answer:
Related Book For
Systems analysis and design
ISBN: 978-0136089162
8th Edition
Authors: kenneth e. kendall, julie e. kendall
Posted Date:
Students also viewed these databases questions
-
Q6. Let c = For j = 1,2..., define g; on R by C gj(t) = if
-
Do some amendment and enhance the given research paper: Table of Content Abstract..3 Action Research.4 Research Methodology and Design...5 Literature Review: NoSQL Database7 Proposal.7 Iteration 1..8...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Spencer Company sells lamps and other lighting fixtures. The purchasing department manager prepared the following inventory purchases budget. Spencers policy is to maintain an ending inventory...
-
Sweety Tea (ST) manufactures a range of designer T-shirts, which it produces to order for major department stores. On to March the sales department at ST received an order from retail company, Legend...
-
Use data from Table 2.1 to verify that (a) The mass of electrons is about 1/2000 that of H atoms; (b) The mass-to-charge ratio (m/e) for positive ions is considerably larger than that for electrons....
-
What forensic technique was used by CocaCola to prosecute the secretary who was convicted for attempting to sell product information to Pepsi? a. Invigilation b. Interviews c. Videotape d. Net worth...
-
The Bruhaha Brewery is planning to expand internationally. The company has identified six critical location factors and their relative weights. The scores for each of the three potential sites are...
-
Pets Plus, Inc. produces otic fluid for dogs. The otic fluid is sold in 12-ounce plastic bottles. The sales budget for the first four months of the year is as follows: Unit Sales 80,000 January...
-
1. Using the spreadsheet model from Case 2.1 as a starting point, use Solver to find the optimal set of projects to approve. The solution should maximize the total NPV from the approved projects, and...
-
Required information The following information applies to the questions displayed below The stockholders' equity section of TVX Company on February 4 follows Y On February the drectors declare a 2%...
-
How would you describe HR analytics in one simple sentence? Do you believe most HR professionals fear analytics? Why or why not? How can HR analytics improve employee engagement and performance?...
-
The Sigma value of the given process is 6 , identify the Cpk value. Z value = 6 ...
-
What are the technological challenges in e-commerce? What role will virtual and augmented reality play in e-commerce in future?
-
How do you prepare literature review of exploration of the affecting challenge of perfomance of a company.
-
How nurses who belong to Sigma Theta Tau International Honor Society of Nursing (Sigma) can demonstrate collegiality? & How can professional nurses collaborate with and support other nurses and...
-
The books and records of Pluto, an S corporation since 1982, reflect the following for the current year (Pluto is a calendar-year taxpayer): Accumulated adjustments account as of 1/1/current year...
-
The following data are supplied for the common stocks of Nikola Corporation, Tesla, Inc. and General Motors: Nikola Corp (NKLA) Tesla Inc. (TSLA) Close Price ($) Close Price ($) 67.53 30.00 40.81...
-
Define the top-down approach as it relates to drawing data flow diagrams.
-
What are nominal scales used for?
-
Youve sampled the email messages that have been sent to several middle managers of Sawders Furniture Company, which ships build-your-own particleboard furniture across the country. Here is one that...
-
Mark Weinstein has been working on an advanced technology in laser eye surgery. The technology is expected to be available to the medical industry two years from today and will generate annual income...
-
IDEC Pharmaceuticals is considering a drug project that costs \($100,000\) today and is expected to generate end-of-year annual cash flow of \($50,000\) forever. At what discount rate would IDEC be...
-
Should you buy an asset that will generate income of \($1,200\) per year for eight years? The price of the asset is \($6,200\) and the annual interest rate is 10 percent.
Study smarter with the SolutionInn App