def deleteRestaurant(restaurant_id):
    if request.method == 'POST':
        deleteRestaurantById(restaurant_id)
        flash ("Restaurant Deleted")
        return redirect(url_for('restaurantList', restaurants = getRestaurants()))
    else:
        return render_template('deleterestaurant.html', restaurants = getRestaurants(), restaurant_id = restaurant_id, restaurant = getRestaurantById(restaurant_id))
 def do_POST(self):
     try:
         if self.path.endswith("/createRestaurant"):
             ctype, pdict = cgi.parse_header(
                 self.headers.getheader('content-type'))
             if ctype == 'multipart/form-data':
                 self.send_response(301)
                 self.send_header('Content-type', 'text/html')
                 self.send_header('Location', '/restaurants')
                 self.end_headers()
                 fields = cgi.parse_multipart(self.rfile, pdict)
                 messageContent = fields.get('newName')
                 createNewRestaurant(messageContent[0])
                 return
             else:
                 self.send_response(405)
                 self.header_('Content-type', 'text/html')
                 self.end_headers()
                 output = ""
                 output += "Error submitting form"
                 self.wfile.write(output)
                 print (output)
         if self.path.endswith("/editRestaurant"):
             ctype, pdict = cgi.parse_header(
                 self.headers.getheader('content-type'))
             if ctype == 'multipart/form-data':
                 restaurantId = (re.findall('\d{1}', self.path))[0]
                 self.send_response(301)
                 self.send_header('Content-type', 'text/html')
                 self.send_header('Location', '/restaurants')
                 self.end_headers()
                 fields = cgi.parse_multipart(self.rfile, pdict)
                 messageContent = fields.get('newRestaurantName')
                 editRestaurant(messageContent[0], restaurantId)
                 return
             else:
                 self.send_response(405)
                 self.send_header('Content-type', 'text/html')
                 self.send_header('Location', '/restaurants')
                 self.end_headers()
                 output = ""
                 output += "Error editing restaurant"
                 self.wfile.write(output)
                 print (output)
         if self.path.endswith("/deleteRestaurant"):
             ctype, pdict = cgi.parse_header(
                 self.headers.getheader('content-type'))
             if ctype == 'multipart/form-data':
                 restaurantId = (re.findall('\d{1}', self.path))[0]
                 self.send_response(301)
                 self.send_header('Content-type', 'text/html')
                 self.send_header('Location', '/restaurants')
                 self.end_headers()
                 deleteRestaurantById(restaurantId)
                 return
             else:
                 self.send_response(405)
                 self.send_header('Content-type', 'text/html')
                 self.send_header('Location', '/restaurants')
                 self.end_headers()
                 output = ""
                 output += "Error deleting restaurant"
                 self.wfile.write(output)
                 print (output)
     except Exception as inst:
         print ("Error with post request: ")
         print (type(inst))
         print (inst.args)
         print (inst)