I want to be able to collect basic statistics on the use of the web application by users, both anonymous and registered.
The generality here is that, using session identifiers, I could store data for registered users as well as for logging in, and also be able to associate the saved statistics with this session (who belongs to the session is not significant).
However, I run into problems collecting session_key , as it does not appear when an anonymous user logs in to the site (presumably because Django sessions are only saved after the change .
When I check the view with a registered user:
def create(request, *args, **kwargs): print request.session.session_key
For the registered user, session_key is printed. For a registered user or anonymous user, this is None . At the first request to the site, the session does not exist and, therefore, is not available for presentation.
My current plan is to create custom middleware as a subclass for middleware, but overriding process_request() to create sessions for those who don't have session.save() .
My only problem with this approach is that I'm not sure if this will have unintended consequences for other parts of Django - do people have any suggestions?
jvc26 source share