title: both jQuery and $ is not a function
body: <p>I already imported </p>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>under the head section. But still I got,</p>
  
  <pre><code>RelatedObjectLookups.js:142 Uncaught TypeError: $ is not a function
      at RelatedObjectLookups.js:142
      at RelatedObjectLookups.js:175
  (anonymous) @ RelatedObjectLookups.js:142
  (anonymous) @ RelatedObjectLookups.js:175
  (index):177 Uncaught TypeError: $ is not a function
      at (index):177
  </code></pre>
  
  <p>Relavant html looks like,</p>
  
  <pre><code>&lt;head&gt;
  
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  
  
      &lt;script crossorigin="anonymous" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"&gt;&lt;/script&gt;
  &lt;script crossorigin="anonymous" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;link crossorigin="anonymous" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" rel="stylesheet"&gt; 
  &lt;/head&gt;
  &lt;body&gt;
  &lt;script type="text/javascript" src="/admin/jsi18n/"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/static/admin/js/core.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/static/admin/js/admin/RelatedObjectLookups.js"&gt;        &lt;/script&gt;
  
  &lt;script type="text/javascript" src="/static/admin/js/jquery.init.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/static/admin/js/actions.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/static/admin/js/calendar.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="/static/admin/js/admin/DateTimeShortcuts.js"&gt;&lt;/script&gt; 
  {{form.media}}
  &lt;div class="row"&gt;
      &lt;div class="col-6"&gt;
          &lt;form method="post" id="extendTrialForm" class="form"&gt;
              {% csrf_token %}
              {% bootstrap_field form.user %}
              {% bootstrap_field form.core_instance %}
              {% bootstrap_field form.expiry_datetime %}
              {% buttons %}
                  &lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;
              {% endbuttons %}
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;script&gt;
  
  $( document ).ready(function() { // line no 177
  </code></pre>
  
  <p>Removing the script tags above <code>{{form.media}}</code> won't throw any error related to jquery but it misses the widget functionality. I need that script tags but I don't want Jquery to return <code>$</code> is not a function. I have tried adding <code>$.noconflict</code>, <code>jQuery(document).ready</code> but nothing works.</p>
  
  <p><code>RelatedObjectsLookups.js</code></p>
  
  <pre><code>/*global SelectBox, interpolate*/
  // Handles related-objects functionality: lookup link for raw_id_fields
  // and Add Another links.
  
  (function($) {
      'use strict';
  
      // IE doesn't accept periods or dashes in the window name, but the element IDs
      // we use to generate popup window names may contain them, therefore we map them
      // to allowed characters in a reversible way so that we can locate the correct
      // element when the popup window is dismissed.
      function id_to_windowname(text) {
          text = text.replace(/\./g, '__dot__');
          text = text.replace(/\-/g, '__dash__');
          return text;
      }
  
      function windowname_to_id(text) {
          text = text.replace(/__dot__/g, '.');
          text = text.replace(/__dash__/g, '-');
          return text;
      }
  
      function showAdminPopup(triggeringLink, name_regexp, add_popup) {
          var name = triggeringLink.id.replace(name_regexp, '');
          name = id_to_windowname(name);
          var href = triggeringLink.href;
          if (add_popup) {
              if (href.indexOf('?') === -1) {
                  href += '?_popup=1';
              } else {
                  href += '&amp;_popup=1';
              }
          }
          var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');
          win.focus();
          return false;
      }
  
      function showRelatedObjectLookupPopup(triggeringLink) {
          return showAdminPopup(triggeringLink, /^lookup_/, true);
      }
  
      function dismissRelatedLookupPopup(win, chosenId) {
          var name = windowname_to_id(win.name);
          var elem = document.getElementById(name);
          if (elem.className.indexOf('vManyToManyRawIdAdminField') !== -1 &amp;&amp; elem.value) {
              elem.value += ',' + chosenId;
          } else {
              document.getElementById(name).value = chosenId;
          }
          win.close();
      }
  
      function showRelatedObjectPopup(triggeringLink) {
          return showAdminPopup(triggeringLink, /^(change|add|delete)_/, false);
      }
  
      function updateRelatedObjectLinks(triggeringLink) {
          var $this = $(triggeringLink);
          var siblings = $this.nextAll('.change-related, .delete-related');
          if (!siblings.length) {
              return;
          }
          var value = $this.val();
          if (value) {
              siblings.each(function() {
                  var elm = $(this);
                  elm.attr('href', elm.attr('data-href-template').replace('__fk__', value));
              });
          } else {
              siblings.removeAttr('href');
          }
      }
  
      function dismissAddRelatedObjectPopup(win, newId, newRepr) {
          var name = windowname_to_id(win.name);
          var elem = document.getElementById(name);
          if (elem) {
              var elemName = elem.nodeName.toUpperCase();
              if (elemName === 'SELECT') {
                  elem.options[elem.options.length] = new Option(newRepr, newId, true, true);
              } else if (elemName === 'INPUT') {
                  if (elem.className.indexOf('vManyToManyRawIdAdminField') !== -1 &amp;&amp; elem.value) {
                      elem.value += ',' + newId;
                  } else {
                      elem.value = newId;
                  }
              }
              // Trigger a change event to update related links if required.
              $(elem).trigger('change');
          } else {
              var toId = name + "_to";
              var o = new Option(newRepr, newId);
              SelectBox.add_to_cache(toId, o);
              SelectBox.redisplay(toId);
          }
          win.close();
      }
  
      function dismissChangeRelatedObjectPopup(win, objId, newRepr, newId) {
          var id = windowname_to_id(win.name).replace(/^edit_/, '');
          var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
          var selects = $(selectsSelector);
          selects.find('option').each(function() {
              if (this.value === objId) {
                  this.textContent = newRepr;
                  this.value = newId;
              }
          });
          win.close();
      }
  
      function dismissDeleteRelatedObjectPopup(win, objId) {
          var id = windowname_to_id(win.name).replace(/^delete_/, '');
          var selectsSelector = interpolate('#%s, #%s_from, #%s_to', [id, id, id]);
          var selects = $(selectsSelector);
          selects.find('option').each(function() {
              if (this.value === objId) {
                  $(this).remove();
              }
          }).trigger('change');
          win.close();
      }
  
      // Global for testing purposes
      window.id_to_windowname = id_to_windowname;
      window.windowname_to_id = windowname_to_id;
  
      window.showRelatedObjectLookupPopup = showRelatedObjectLookupPopup;
      window.dismissRelatedLookupPopup = dismissRelatedLookupPopup;
      window.showRelatedObjectPopup = showRelatedObjectPopup;
      window.updateRelatedObjectLinks = updateRelatedObjectLinks;
      window.dismissAddRelatedObjectPopup = dismissAddRelatedObjectPopup;
      window.dismissChangeRelatedObjectPopup = dismissChangeRelatedObjectPopup;
      window.dismissDeleteRelatedObjectPopup = dismissDeleteRelatedObjectPopup;
  
      // Kept for backward compatibility
      window.showAddAnotherPopup = showRelatedObjectPopup;
      window.dismissAddAnotherPopup = dismissAddRelatedObjectPopup;
  
      $(document).ready(function() {
          $("a[data-popup-opener]").click(function(event) {
              event.preventDefault();
              opener.dismissRelatedLookupPopup(window, $(this).data("popup-opener"));
          });
          $('body').on('click', '.related-widget-wrapper-link', function(e) {
              e.preventDefault();
              if (this.href) {
                  var event = $.Event('django:show-related', {href: this.href});
                  $(this).trigger(event);
                  if (!event.isDefaultPrevented()) {
                      showRelatedObjectPopup(this);
                  }
              }
          });
          $('body').on('change', '.related-widget-wrapper select', function(e) {
              var event = $.Event('django:update-related');
              $(this).trigger(event);
              if (!event.isDefaultPrevented()) {
                  updateRelatedObjectLinks(this);
              }
          });
          $('.related-widget-wrapper select').trigger('change');
          $('body').on('click', '.related-lookup', function(e) {
              e.preventDefault();
              var event = $.Event('django:lookup-related');
              $(this).trigger(event);
              if (!event.isDefaultPrevented()) {
                  showRelatedObjectLookupPopup(this);
              }
          });
      });
  
  })(django.jQuery);
  </code></pre>