The session framework can be used to provide persistent behavior for anonymous users on a website. Sessions — it is the mechanism Django uses to store and retrieve data for each site visitor. Django uses a cookie that contains a special session identifier.
To enable a session in django, you need to make sure two things in
After enabling the session, the session database table must be created and to do this run the following command:
python manage.py syncdb pre>
After running the previous command and if it doesn`t find any errors, then run the command below to finally reflect the changes saved in the migration file in the database.python manage .py migrate
Now that the sessions are created, you need to test your cookies. In
views.py, set a test cookie in the index view and test the cookie in your about view.
all code >
"dhun / home.html"
request.session.test_cookie_worked ():p >
request.session.delete _test_cookie ()
To see the work done so far.
python manage.py runserver
To see how many times a site has been visited. There are two things you need to do in views.py: