404 Not Found
The path '/getCustomer' was not found.
Traceback (most recent call last):
File "C:\Python33\virtualenviorments\cherrypro\lib\site-packages\cherrypy\_cprequest.py", line 670, in respond
response.body = self.handler()
File "C:\Python33\virtualenviorments\cherrypro\lib\site-packages\cherrypy\lib\encoding.py", line 212, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "C:\Python33\virtualenviorments\cherrypro\lib\site-packages\cherrypy\_cperror.py", line 411, in __call__
raise self
cherrypy._cperror.NotFound: (404, "The path '/getCustomer' was not found.")
i get this error when i try to display the table from user selected from dropdown .... here is the py code
import cherrypy
import sqlite3
from jinja2 import Environment, FileSystemLoader
fileSystemLoader = FileSystemLoader('templates')
env = Environment(loader = fileSystemLoader)
class Root:
@cherrypy.expose
def index(self):
self.getNames() # For the drop down menu
tmpl = env.get_template('index6.html')
return tmpl.render(salutation ='Welcome to',
target =' Supershop',
myList = self.nameList)
@cherrypy.expose
def getOneCustomer(self, customerName = None):
if str(customerName) =='Select': # Nobodys name selected
custList = ['', 'Select name']
else:
custList = self.getCustomer(customerName)[0]
self.getNames() # For the drop down menu
tmpl = env.get_template('index6.html')
return tmpl.render(salutation = 'Welcome to',
target = ' Supershop',
myList = self.nameList,
customerList = custList)
def connect(self):
# Get the connection to the database
self.conn=sqlite3.connect('supershop')
# Get the cursor object for the database
self.cursor=self.conn.cursor()
def getNames(self):
self.nameList = [] # Reset the nameList
self.connect() # Make connection to DB and get cursor
# Select the name column from the database
self.cursor.execute("""
SELECT customerTable.name
FROM customerTable ORDER BY customerTable.name """)
self.conn.commit()
# Fill the names into the nameList
for row in self.cursor.fetchall(): # Get tuple of tuples
for field in row: # Iterate over "name tuple"
self.nameList.append(field)
self.cursor.close()
self.conn.close()
def getCustomer(self, customerName):
self.connect() # Make connection to DB and get cursor
self.cursor.execute("""
SELECT customerTable.idCust, customerTable.name,
customerTable.email, customerTable.address, customerTable.city
FROM customerTable WHERE customerTable.name = ? """,
(customerName,)) # MUST be a tuple. Don’t forget the comma!
self.conn.commit()
self.DBcustList = list(self.cursor.fetchall())
self.cursor.close()
self.conn.close()
return self.DBcustList
cherrypy.config.update({'server.socket_host': '127.0.0.1',
'server.socket_port': 8080,
})
cherrypy.quickstart(Root())
and here the html code
<h1>{{salutation}}{{target}}</h1>
<p>Select a name from thee list:</p>
<form action='getOneCustomer' method='post'>
<u1>
<select name = 'customerName'>
{%for n in myList%}
<option>{{n}}</option>
{%endfor%}
</select>
</u1>
<p><input type='submit' value='Submit'/></p>
</form>
<p>Customer data:</p>
<table style='width:300px'>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Address</th>
<th>City</th>
</tr>
<tr>
{%for n in customerTuple%}
<td>{{n}}</td>
{%endfor%}
</tr>
</table>
How do I get the path to be accessible correctly?
The only thing that sticks out to me is in your template you reference customerTuple however in your render command you use customerList.
Hope this helps!