Link generator using django or any python module
Question: I want to generate for my users temporary download link. Is that ok if i use
django to generate link using url patterns? Could it be correct way to do
that. Because can happen that I don't understand some processes how it works.
And it will overflow my memory or something else. Some kind of example or
tools will be appreciated. Some nginx, apache modules probably?

So, what i wanna to achieve is to make url pattern which depend on user and
time. Decript it end return in view a file.


Answer: A simple scheme might be to use a hash digest of username and timestamp:

    
    
    from datetime import datetime
    from hashlib import sha1
    
    user = 'bob'
    time = datetime.now().isoformat()
    plain = user + '\0' + time
    token = sha1(plain)
    print token.hexdigest()
    "1e2c5078bd0de12a79d1a49255a9bff9737aa4a4"
    

Next you store that token in a memcache with an expiration time. This way any
of your webservers can reach it and the token will auto-expire. Finally add a
Django url handler for '^download/.+' where the controller just looks up that
token in the memcache to determine if the token is valid. You can even store
the filename to be downloaded as the token's value in memcache.

