title: JQuery, how to pass the slug variable
body: <p>I'd like to know how I can pass the slug variable into JQuery/javascript.</p>
  <p>I have a data-table with items, on each row there are two buttons, one (1) is using Django to create a product, the other (2) is supposed to use JQuery / JS to create a product.</p>
  <p>To create a product with button 1 I find being straight forward and well explained.</p>
  <p>I'd like to perform the same action on button 2, using JQuery/JS.</p>
  <h2>button 1</h2>
  <pre><code> &lt;a href=&quot;{% url 'products-create' object.products_uid %}&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;btn btn-secondary&quot;&gt;&lt;i class=&quot;fa fa-pencil&quot;&gt;&lt;/i&gt;&lt;/button&gt;&lt;/a&gt;
  </code></pre>
  <p>with urls path:</p>
  <pre><code>path(&quot;products/&lt;uuid:slug&gt;/create/&quot;, ProductsCreateView.as_view(), name=&quot;products-create&quot;),
  </code></pre>
  <p>views.py</p>
  <pre><code>class ProductsCreateView(CreateView):
      model = Products
      template_name = &quot;products_create.html&quot;
      slug_field = &quot;products_uid&quot;
  </code></pre>
  <h2>button 2</h2>
  <pre><code> &lt;button class=&quot;btn btn-secondary js-create-button&quot; data-url=&quot;{% url 'api-products-create' object.products_uid %}&quot; type=&quot;button&quot;&gt;&lt;span class=&quot;fa fa-pencil&quot;&gt;&lt;/span&gt;&lt;/button&gt;
  </code></pre>
  <p>with urls path:</p>
  <pre><code>path('api/products/&lt;uuid:slug&gt;/create/', ProductsCreateView.as_view(), name=&quot;api-products-create&quot;),
  </code></pre>
  <p>with js (truncated function)</p>
  <pre><code>$(function () {
  
      var createProduct = function() {
          var slug = '{{ $slug }}';  /* some code/function that gets hold of the slug */
          const url = `/api/v1/products/${slug}/create/`;
         
          $.get(url)
          .done(function pollAsyncResults(data) {
            // bind pollAsyncResults to itself to avoid clashing with
            // the prior get request
            context: this
            // see the URL setup for where this url came from
            const pollAsyncUrl = `/api/products/poll_async_results/${data.task_id}`;
          })
      };
  
     $(&quot;.js-create-button&quot;).click(createProduct);
  
  });
  </code></pre>