get_add_to_basket_url method not working

I am using this method inside Product Class get_add_to_basket_url to add item to basket but link not working, hope anyone can help with this.

this is the Link address from Add To Cart Button


Page Not Found 404 for this Url above


				<div class="extra content">
					<span class="right floated">
						<i class="money bill alternate icon"></i>
						Final Price: {{ product.price }}
					{% if product.before_price %}
						<i class="money bill alternate outline icon"></i>
						Old Price: <del class="DublStrk">{{ product.before_price }}</del>
					{% endif %}
				<div class="extra content">
					<a class="ui fluid button" href="{( product.get_add_to_basket_url )}">Add To Basket</a>

Method in Product Model

    from django.urls import reverse_lazy

	def save(self, *args, **kwargs):
		if not self.slug:
			self.slug = slugify(f'{}-{self.sku}')
		super(Product, self).save(*args, **kwargs)

	def get_absolute_url(self):
		return reverse_lazy('Products:ProductPageUrl', kwargs={'slug': self.slug})
	def get_add_to_basket_url(self):
		return reverse_lazy('Baskets:ItemAddToBasketUrl', kwargs={'slug': self.slug})

	def __str__(self):
		return f'{} - {self.sku}'


app_name = 'Baskets'
urlpatterns = [
	path('add-to-basket/<slug:slug>', views.ItemAddToBasketView, name='ItemAddToBasketUrl'),


def ItemAddToBasketView(request, slug):
	item = Product.objects.filter(slug=slug)
	order_item, created = OrderItem.objects.get_or_create(item=item, account=request.user, ordered=False)
	order_qs = Order.objects.filter(account=request.user, ordered=False)
	if order_qs.exists():
		order = order_qs[0]
		if order.items.filter(item__slug=item.slug).exists():
			order_item.quantity += 1
			message.success(request, f'{item} added Quantity is Updated in Basket.')
			return redirect('Products:ProductPageUrl')
			message.success(request, f'{item} added to Basket.')
			return redirect('Products:ProductPageUrl')
		order = Order.objects.create(account=request.user, ordered=False, ordered_at=ordered_at)
		return redirect('Products:ProductPageUrl')

Hey there!
It looks like you mispelled the {{ with {( → Notice the parenthesis:

1 Like

I notice this by seeing the url you just posted

If you got a URL decoder you’ll see that this is the result:
http://localhost:8000/products/product/{( product.get_add_to_basket_url )}

1 Like

Very Thankful my friend. it works now.