You can simple use inbuilt user authentication provided by django.
What problem are you facing with it?
Any way if you are interested in building your own authentication
engine you need to do the following:
you can do this in several way one way is
1) Store cookie in user browser (you can store the user id (or) you
can give unique session id to this user and store relevant information
in the backend database)
like :
userid ============> sessionid
2) write down your middleware to check whether the request is bringing
any cookie associated with it or not.
if yes pull the sessionid and associate the request with this user
if no means no user has logged in.
--rama