Нужно пробросить данные user_filter и datas из def login_view в def index_view, чтобы затем эти данные передать в home.html
def login_view(request, *args, **kwargs):
form = UserLoginForm(request.POST or None)
test = 'asdasdasd'
if form.is_valid():
user_obj = form.cleaned_data.get('user_obj')
login(request, user_obj)
conn_string = "host='localhost' dbname='askue_rs_test' user='developer' password='developer'"
conn = psycopg2.connect(conn_string)
cursor = conn.cursor()
user = str(user_obj)
cursor.execute("SELECT filter_department FROM accounts_myuser WHERE username = %s", [user])
user_filter = cursor.fetchall()
elem = (str(user_filter).lstrip("[('").rstrip("\\',)]") + "%")
print(elem)
cursor.execute("SELECT filter_dep from test_data WHERE filter_dep LIKE %s", (elem,))
datas = cursor.fetchall()
#print(datas)
return HttpResponseRedirect("/")
return render(request, "registration/login.html", {"form": form})
def indexView(request):
return render(request, 'home.html')