Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango: LDAP search results disappear
    primarykey
    data
    text
    <p>Why in the code below, does the global <code>direktorie</code> return the correct data in the <code>login()</code> debug template, yet when I try to access the same variable from <code>autoname()</code> it says the list has a length of <code>0</code>? I don't reference <code>direktorie</code> in any other places in <code>views.py</code> -- or anywhere else for that matter. (All of the code below is merely an attempt to discover what I'm doing wrong. I don't really care about the length of the returned list. I just want to know it's being seen and has roughly the right number of entries.)</p> <pre><code>from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.shortcuts import render_to_response, get_object_or_404 import json # JSON for jQuery AJAX autocomplete from eldappery import * # LDAP for jQuery AJAX autocomplete direktorie = [] ############################################################################## def login(request): """LDAP Login routine""" global direktorie if request.method == "POST": # If submitted... if request.POST["username"] and request.POST["password"]: username = request.POST["username"] password = request.POST["password"] LDAPfeed = dapperize(username, password) # ...login if LDAPfeed: direktorie = fetch_names(LDAPfeed,"") # ...get everybody ls = locals() # DEBUG! gs = globals() # DEBUG! return render_to_response("debug.html", {"ls": ls, "gs": gs}) # DEBUG! Works! (direktorie full) else: return HttpResponseRedirect("/login/") return render_to_response("login.html", context_instance=RequestContext(request)) ############################################################################## def autoname(request): """Auto-complete names""" global direktorie if request.is_ajax(): # results = [{"id": 5, # "label": 5, # "value": 5}] # DEBUG! Works! (5 in template) results = [{"id": len(direktorie), "label": len(direktorie), "value": len(direktorie)}] # DEBUG! Doesn't work! (0 in template) data = json.dumps(results) # Convert to JSON string else: # No results returned! data = "fail" # Error... mimetype = "application/json" # MIME type = JSON return HttpResponse(data, mimetype) # Send JSON back to web page ############################################################################## </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload