NameError - global name not defined

By : rv_k
Source: Stackoverflow.com
Question!

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.
VIEWS.PY

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")
        EmployeeDetails(userName=userName,designation=designation,employeeID=employeeID,contactNumber=contactNumber,project=project,dateOfJoin=dateOfJoin).save()
        return render_to_response('createEmployee.html')
    else:
        return render_to_response('createEmployee.html')

TEMPLATE.PY

<form action="http://127.0.0.1:8000/createEmployee/" 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 />
</form>
By : rv_k


Answers
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'):
'my_username'


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