Page not found (404) error on django
<p>I am trying to get price value as soon as product is selected in sale form. There is a sale form which has field of price, quantity and product. When user selects for product, the price of that product should be shown to the input box of price. For that i have used ajax. </p>

<blockquote>
  <p>But i am getting an error of 404 page not found in sales/price/2. When
  i enter that url in browser i get the result as {"price-pk": 2,
  "price": 890.0}</p>
</blockquote>

<p><strong>The code</strong></p>

<p><strong>sales/views.py</strong></p>

<pre><code>def fetch_price(request, pk):
    response = {}
    product = get_object_or_404(Product, pk=pk)
    print('product',product)
    if request.method=='GET':
        price = product.price
        print('price',price)
        response['price-pk'] = product.pk
        response['price'] = price 
        json_data = json.dumps(response)
        return HttpResponse(json_data, content_type='application/json')
</code></pre>

<p><strong>sales/urls.py</strong></p>

<pre><code>url(r'^price/(?P&lt;pk&gt;\d+)$', views.fetch_price, name='fetch_price'),
</code></pre>

<p><strong>add_sale.html</strong></p>

<pre><code>&lt;script&gt;
        $('#id_product').on('change', function() {
            price_id = $(this).val(); // if shoe is selected price_id value becomes 2 as pk of shoe is 2
            console.log(price_id);
            url = "/sale/price/"+price_id+"/";
            $.ajax({
                type:'GET',
                url:url,
                success: function(data){
                    console.log('price will be updated based on product selected');
                    $('#id_price').val(data.price);
                }
            })
        });
    &lt;/script&gt;
</code></pre>

<p>Your URL pattern doesn't end with a slash, but your Ajax request is for a URL that does end with a slash. Fix one or the other; probably better for consistency to ensure that the pattern has a slash.</p>

<pre><code>r'^price/(?P&lt;pk&gt;\d+)/$'
</code></pre>

javascript python ajax django django-views