NameError - global name not defined

By : rv_k

I am trying to read some data from html forms and insert it into database. Doing so i am stuck with this error "NameError at /createEmployee/ : global name 'get_post_param' is not defined" ; i will paste my code here. Can somebody help me to solve this.

def createEmployee(request):
    if request.method == "POST":
        userName = get_post_param(request,"userName")
        designation = get_post_param(request,"designation")
        employeeID = get_post_param(request,"employeeID")
        contactNumber = get_post_param(request,"contactNumber")
        project = get_post_param(request,"project")
        dateOfJoin = get_post_param(request,"dateOfJoin")
        return render_to_response('createEmployee.html')
        return render_to_response('createEmployee.html')


<form action="" method="POST"> 
Name: <input type="text" name="userName" /><br />
Designation: <input type="text" name="designation" /><br>
EmployeeID: <input type="text" name="employeeID" /><br>
Contact Number: <input type="text" name="contactNumber" /><br>
Project: <input type="text" name="project" /><br>
Date Of Join: <input type="text" name="dateOfJoin" /><br>
<input type="submit" value="Submit" /><br />
By : rv_k

This is a very simple problem. You have not defined get_post_param.
Where did you get this get_post_param idea?

Simply define a function called get_post_param to fix it..

Here's a python shell session

>>> get_post_param(request, 'userName')
NameError: not defined

>>> def get_post_param(request, param):
...    return request.POST.get(param) 
       # or scrap the idea of a function to do a one liner op anyways

>>> get_post_param(request, 'userName'):

This video can help you solving your question :)
By: admin