In my attempts to learn django, I've been trying to make a clone of dayscore.net
. Meaning that, I want to make the site using django, this does not refer to a git clone
or a hg clone
If you take a look, every time a new user comes to dayscore, you get a unique session, with a special hash code. How would you achieve something like this using django?
Asked
Active
Viewed 1,278 times
0

Games Brainiac
- 80,178
- 33
- 141
- 199
-
Django sessions does exactly the same thing. Check out the [documentation](https://docs.djangoproject.com/en/dev/topics/http/sessions/). – Sudipta Jul 15 '13 at 07:25
1 Answers
2
1) As was pointed in the comment to your question Django applies session ID to any request if you have enabled Session middleware.
2) In case you still want to generate session id yourself you can create middleware where on process_request
you'll create hash value and add it to sessions.
middleware.py
import uuid
class AnonHashMiddleware(object):
def process_request(self, request):
"""
If user is not authenticated (anonymous) we set session hashcode
uuid4 hex
"""
if not request.user.is_authenticated() and \
'hashcode' not in request.session:
request.session['hashcode'] = uuid.uuid4().hex
Pros
- No matter what page of the site user comes in if he is anonymous without hashcode he'll get hashcode generated for him.
Cons
- Middleware will be applied for each request coming to the server just like all other middlewares.

shalakhin
- 4,586
- 5
- 25
- 30
-
-
make it precise in your question you want to make such behavior and not just clone (like `wget -r` the site) – shalakhin Jul 15 '13 at 06:41
-
I thought it was clear because you talk about things like a 'facebook clone' and a 'hackernews clone', so I thought this would not cause confusion. I mean, when was the last time you wanted to clone an actual site? – Games Brainiac Jul 15 '13 at 07:10
-
I helped with cloning of the site about 1 week ago for one person willing to learn web development so it wasn't clear for me. Maybe I looked at your question from that perspective – shalakhin Jul 15 '13 at 07:19
-
-
I think the hashcode should be generated when there's no hashcode specified in the URL. I would make a view for `/` URL, which redirect the user to the main view, like what `dayscore.net` does. – Maxime Lorant Jul 15 '13 at 07:38
-
What if the user comes on the page different from `/`? If applying hashcode is implemented in middleware it will give a hashcode don't matter which page of the site user comes which I think is pretty convenient and user-friendly. On the other side your suggestion to use view instead of middleware reduces number of middlewares – shalakhin Jul 15 '13 at 07:53