title: Django Autocomplete Light - "The results could not be loaded"
body: <p>I'm using Django-autocomplete-light on a small application. The UI seems to work, and I can select from some visible values. The problem arises when I type one or more letters into the box. Normally it should filter/select the results, instead, I get the error "The results could not be loaded" (see picture).</p>
  
  <p>Seems like the jquery is working fine, except for not filtering when I type in the box. Happy to add more code, just not sure what I need to add yet.</p>
  
  <p><strong><em>models.py</em></strong></p>
  
  <pre class="lang-py prettyprint-override"><code>class Encounter(models.Model):
      patid = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, verbose_name=('Patient Name'), related_name='patient')
      created_by = models.ForeignKey(Users, editable=False, null=True, blank=True, on_delete=models.PROTECT, related_name='encounter_created_by')
      encounter_date = models.DateField()
      encounter_label = models.ForeignKey(EncounterReason, on_delete=models.PROTECT, verbose_name=('Encounter Reason'), related_name='fk_reason')
  
  class EncounterReason(models.Model):
      reason = models.CharField(max_length=256, blank=True, null=True)
      valueset_id = models.CharField(max_length=256, blank=True, null=True)
  
  </code></pre>
  
  <p><strong><em>views.py</em></strong></p>
  
  <pre class="lang-py prettyprint-override"><code>class EncounterReasonAutocomplete(autocomplete.Select2QuerySetView):
      def get_queryset(self):
          # Don't forget to filter out results depending on the visitor !
          if not self.request.user.is_authenticated:
              return EncounterReason.objects.none()
          qs = EncounterReason.objects.all()
          if self.q:
              qs = qs.filter(name__istartswith=self.q)
          return qs
  </code></pre>
  
  <p><strong><em>forms.py</em></strong></p>
  
  <pre class="lang-py prettyprint-override"><code>class EncounterForm(forms.ModelForm):
      encounter_date = forms.DateField(initial=datetime.date.today, widget = DateInput())
      encounter_notes = forms.CharField(widget=forms.Textarea(attrs={'placeholder': 'Encounter Notes', 'id': 'editor', 'rows':50, 'cols':25}))
      encounter_label = forms.ModelChoiceField(queryset=EncounterReason.objects.all(),
          widget=autocomplete.ModelSelect2(url='encounterreason-autocomplete')
      )
  
      class Meta:
          model = Encounter
          fields = ('__all__')
  
  </code></pre>
  
  <p><strong><em>urls.py</em></strong></p>
  
  <pre class="lang-py prettyprint-override"><code>urlpatterns = [
      path('admin/', admin.site.urls),
      path('accounts/', include('django.contrib.auth.urls')),
      path('', include('clinicalviewer.urls')),
      path('encounterreason-autocomplete/', views.EncounterReasonAutocomplete.as_view(),
           name='encounterreason-autocomplete'),
  ]
  </code></pre>
  
  <p>Without typing anything into the box:
  <a href="https://i.stack.imgur.com/me5yY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/me5yY.png" alt="enter image description here"></a></p>
  
  <p>Now when I type something into the box (there are objects that start with "r"):
  <a href="https://i.stack.imgur.com/XF9Vv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XF9Vv.png" alt="enter image description here"></a></p>
  
  <p><strong><em>Errors:</em></strong>
  In the console I get the following error:
  jquery.js:9203 GET <a href="http://127.0.0.1:8000/encounterreason-autocomplete/?q=r" rel="nofollow noreferrer">http://127.0.0.1:8000/encounterreason-autocomplete/?q=r</a> 500 (Internal Server Error)</p>