#-*- coding:utf-8 -*-
from django.db import connection
class MyMiddleware(object):
def process_request(self, request):
if request.user.is_authenticated():
cursor = connection.cursor()
cursor.execute("SELECT set_config('var.user_id', %s::text, true)", [request.user.pk])