Preview

5 - Full Stack - putting it all together!

 1. Line 1 in the following form, in order for it to allow comments to be entered into the form and be stored in the database, should be: form action="http://127.0.0.1:5000/add" method="get"
<form action="http://127.0.0.1:5000/add">
  <div class="form-group">
    <label for="exampleInputEmail1">Name</label>
    <input type="text" class="form-control" id="title" name="title" aria-describedby="emailHelp">
  </div>
  <div class="form-group">
    <label for="exampleInputPassword1">Title (or catchy caption!)</label>
    <input type="text" class="form-control" id="name" name="name">
  </div>
  <div class="form-group">
  <label for="exampleFormControlTextarea1">Add your amazing answer here:</label>
  <textarea class="form-control" id="comment" name="comment" rows="3">

  False

  True

 2. Flask has different decorators to handle HTTP requests. The Hypertext Transfer Protocol (HTTP) is designed to ___________________________.

  enable communications between servers and the programmer.

  enable uploading and downloading from a server.

  enable communications between clients and servers.

  enable communications between browsers and users.

 3. Consider the following table. Fill in the blanks for the POST request definition.
Different methods for retrieving data from a specified URL 
are defined in the HTTP protocol. 

The following table gives a summary of the different http methods:

Request  Purpose
=====================================================================
 GET	 The most common method. A GET message is sent, and 
         the server returns data
 
 POST	 Used to send _____________________________________?
         The data received by the POST method is not cached by the server.
 
 HEAD	 Same as GET method, but no response body.
 
 PUT	 Replace all current representations of the target resource 4
         with uploaded content.
 
 DELETE	 Deletes all current representations of the target resource 
         given by the URL.

  HTML form data back to the browser

  HTML get data to the client

  HTML form data to the server.

  HTTP requests to the browser

 4. To access incoming data in Flask, we use the request object. The request object holds all incoming data from the request, which includes the mimetype, referrer, IP address, raw data, ___________, and headers, among other things.
To gain access to the request object in Flask, 
you simply import it from the Flask library.

from flask import request

  HTTP method

  HTML method

  FORM method

  SQL method

 5. HTTP works as a request-response protocol between a client and server. The two most common HTTP methods are: _____________.

  HTML and UDP

  SELECT and FROM

  GET and POST

  INSERT and DELETE

 6. _____ requests are often used when uploading a file or when submitting a completed web form.

  GET

  HTML

  APP

  POST

 7. The following code is the corresponding function in the main python file that is related to the form. Assuming the request is a POST request, which of the following statements is true?
//@app.route('/add',methods=['GET','POST'])
def addcomment():
    if request.method=="GET":
        return render_template('addcomment.html')
    else:
        user_details=(
        request.form['name'],
        request.form['title'],
        request.form['comment']
            )
        #print(user_details)
        insertcomment(user_details)
        return render_template('addsuccess.html')

  The html page addsuccess.html is rendered on the screen

  All of the listed options are valid answers

  The user_details are taken and stored in the variable user_details

  The contents of user_details are passed to the function insertcomment()

 8. Consider the following python function. (relating to the above two questions). Which of the following statements is most accurate?
def insertcomment(user_details):
        connie = sqlite3.connect(db_locale)
        c=connie.cursor()
        sql_execute_string = 'INSERT INTO comments (title, name, comment) VALUES (?,?,?)';
        c.execute(sql_execute_string,user_details)
        connie.commit
        connie.close()
        print(user_details)

  This function is passed the contents of the variable user_details and these are stored in the database.

  This function is inserting the contents of the database into a string called sql_execute.

  This function is a query that is searching for specific data and INSERTING this data into a variable called user_details if present.

  This function is opening a database connection and inserting the contents of user_details into a table called VALUES.

 9. What is wrong with the following route declaration? Why will it not correctly render the desired page?
#route
@app.route('/addsuccess') 
def addsuccess():
    render_template('addsuccess.html')

  The last line should be: return template('addsuccess.html)

  The @ app.route line should be @app.route(addsuccess())

  the function declaration should be: def addsuccess{}

  The last line should be: return render_template('addsuccess.html')

 10. Modern web applications use meaningful URLs to help users. The route() decorator, as shown in the code below, are used to:
#route
@app.route('/')
def index():
    return 'Index Page'

@app.route('/hello')
def hello():
    return 'Hello, World'

  create a HTML page and link it to a URL

   bind a function to a URL.

  create a URL as part of an HTTP response

  define and dynamically create a HTML page