Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.shortcuts import render_to_response, get_object_or_404
- from django.http import HttpResponsePermanentRedirect
- from django.core.urlresolvers import reverse
- def product(request, slug):
- # Product ID where we start 301 Redirects
- redirect_before = 15
- # If slug is numeric, find the product from Product.id
- if slug.isdigit():
- product = get_object_or_404(Product, id=int(slug))
- # If the slug isn't numeric, we find the product from Product.slug
- else:
- product = get_object_or_404(Product, slug=slug)
- # If the Product.id is equal to or less than redirect_before,
- # we 301 Redirect to our new URL
- if product.id <= redirect_before:
- return HttpResponsePermanentRedirect(reverse('shoppingcart-product', args=[product.slug,]))
- return render_to_response('shoppingcart/product.html', {'product':product})
Add Comment
Please, Sign In to add comment