Does anyone know of any better ways to replace long affiliate URL's with cloaked links or short, such that users only see shortened links开发者_运维技巧.
Something like this : "anothersite.com/offer.html/affiliate_id=001" cloaked like this: "http://site.com/click/offer"
Assuming if there more affiliate links like this, setting up redirection would easily fill up urls.py with more patterns. Django’s built-in generic views provide ways to setup (external) URL redirection applications but just wondering whether there are any better ways to do this without filling the .htaccess or urls.py.
If you want to be able to build on this in the future, you could create your own simple model:
class AffiliateLink(models.Model):
slug = models.SlugField(unique=True)
full_url = models.URLField()
Then create a view to do the redirection:
def affiliate_link(request, slug):
link = get_object_or_404(AffiliateLink, slug=slug)
return redirect(link.full_url)
Then setup the urls file:
(r'^affiliates/(?P<slug>[^/]+/', 'myapp.views.affiliate_link'),
And that it.
Django comes with an additional redirects app.
精彩评论