Blogger Template by Blogcrowds.

     This section will teach you to How to create dynamic menu in templates. Here we used ``context processors``


  • create a file say `` inside your application folder.
  • File looks like
from models import GameCategory
def Category(request):
    return {'category_list':category_list}
  • In
    'MyProject.MyApplication.context_processors.Category', # path to above-said file(
  • Now you can able to get the {{category_list}} in your Base.html

Easy way to Import & Export as CSV file in postgreSQL using psql copy command.


COPY tablename From '/absolute _path_to_file/filename.csv' DELIMITERS '|' WITH NULL AS '';

COPY tablename To '/absolute _path_to_file/filename.csv' DELIMITERS '|' WITH NULL AS '';

  • User should be superuser i.e postgres.
  • Path should be absolute and have full permission (chmod 777).
  • Should be in local-machine where postgreSQL installed.
  • While importing data from csv to DB, the field and data order should be same. (Say, If we have table with fields as ID & Name, then data in csv file should be 1 & Jayapal )


  • Script use to get the pincode from a address. I used regulatr expression to find it. At first, we will check check pincode end of address. If we didn't get, then check between address. Here I assumed pincode starts with 7 and len should be 6 (ex 700002)

def getPin(myStr):"7(\d{0,5})$",myStr)# check for pincode end of string
    if not pin:"7(\d{0,5})[ ]",myStr) # check for pincode in between string
    return pin


  • Simply ignoring NULL characters while reading CSV file.

def nonull(stream):
    for line in stream:
        yield line.replace('\x00', '')

reader = csv.reader(nonull(open(os.getcwd()+"/test.csv")), dialect='excel', delimiter='|')


  • Check whether string is in printable format. This would be useful when we parse unformatted csv file.

def check(myStr):
    return filter(lambda x: x in string.printable, myStr)


  • I like to share Django Python interivew question which I attended during Sep & Oct 2010

1.How django works (work flow)
2.what is inisde application folder?
3.What is the use of you will add extra function/feature in admin part
5.have you customized admin style?
6.what are all middleware you used and whats the purpose ot it? you used session ? How can we handle session expire time ? you will write django complex query?
9.Django group_by query
10.what is signals and how to use it? What are two important parameter in signals?
11.Have you write templatetags? Whats the use of it?
12.form inheritance
13.model inheritance
14.How to get all logged-in user list or count
15.what are all reusable application u used in django prjt dynamic data without using DB/file.
17.How you are requesting ajax in django? How it works? u ill access a particular block in child html? u are debugging applicaiton?
20.logging module have u used ?
21.What is message framework and explain it
22.what are modules in django?
23.What is serialization and why we are using it?
24.How you are testing your application?
25.How you are deploying applicaiton with apache?
26.Whats the difference between mod_python & mod_wsgi
27.What are all new featues in django latest version
28.whats major advantage in django 1.2
29.which function wont run in django 1.2 which runs in django 1.0
30. If Django powerd application is high traffi site then how you will reduce the traffic?
31. How to modify model without affecting datas?
32. What are things we have to consider while designing models

1.What is datatype(this is first question asked b y all interviewer)
2.list, tuple, dict diff
3.list sorting without using generic function
4.can we use list as key in dict?
5.Dict sorting both key and value sorting
6.what is Listcomprehension and where you use it?
7.What is iterator, generator?
8.How to get traceback? expalin to write class
10.what is __init__
11.what is self
12.wts is constructor
13.wts decorator ? How it works? How to write custom decorator?
14.wts is __init__ and __new
15.wts is super function in python and where you ill use
16.hv u used set() ? if so wr (Note that Set() depreciated in python 2.6)
17.single linked list?
18.Which version you are using?
19.Deprecation in python latest version or version which you are working

1.If we modify a models, then error will arise while accessing admin? Hw can we fix it? data shoouldn't miss from table
2.if the modified models filed is primary then how can we do that?
3.if the primary key is override then how can we do it?
4.if the primary key is from another table as foregin key, then hwo can we do it?
5.DB master, slave,cluster?
6.Table joining query

Newer Posts Older Posts Home