{"id":83717,"date":"2021-08-14T09:00:08","date_gmt":"2021-08-14T03:30:08","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=83717"},"modified":"2021-08-14T09:00:08","modified_gmt":"2021-08-14T03:30:08","slug":"django-session","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/django-session\/","title":{"rendered":"Django Session- Learn the Steps to Manage Sessions in Django"},"content":{"rendered":"<p>In our previous article, we covered Django Cookies. Let&#8217;s take it a step further and look at Session in Django.<\/p>\n<p>Let&#8217;s take a quick look at the concept of cookies and look at some of its disadvantages. And how the concept of Sessions helped web developers in making their jobs easier.<\/p>\n<h3>What are cookies?<\/h3>\n<p>Cookies are text files created and organised by your browser in response to a specific Web-Server request, as we mentioned previously in the article about cookie handling.<\/p>\n<p>The HTTP protocol is stateless. In other words, when you send a request to the server, it has no notion if you are requesting the page for the first time or if you are the same user who has visited the website thousands of times previously.<\/p>\n<p>Because persistence among requests may be used to promote products or display products in a shopping cart, the absence of statelessness was a major issue for e-commerce website developers. Cookies were created to alleviate this difficulty.<\/p>\n<p>Cookie was initially used in the Netscape Browser in 1994 by a programmer named Louis Montulli.<\/p>\n<h3>Limitations of Cookies<\/h3>\n<ul>\n<li>It is possible to trace users.<\/li>\n<li>The cookies can be deleted by the client.<\/li>\n<li>A cookie can store up to 4096 bytes of information.<\/li>\n<li>Cookies can be stored by both the browser and the server.<\/li>\n<li>Cookies are plain text files, and attackers can easily intercept cookies that are not delivered via HTTPS.<\/li>\n<\/ul>\n<h3>What exactly are Sessions in Django?<\/h3>\n<p>Following these issues with cookies, web developers introduced Sessions, a new and more secure approach.<\/p>\n<p>Let&#8217;s take a closer look at its technical term.<\/p>\n<p>Stateless HTTP is used for all communication between web browsers and servers. As the protocol is stateless, messages between the client and server are completely independent of one another; there is no &#8220;sequence&#8221; or behaviour concept based on prior messages. As a result, if you want a website that keeps track of ongoing client interactions, you&#8217;ll have to build it yourself.<\/p>\n<p>Django (and most of the web framework) uses sessions to maintain track of the &#8220;state&#8221; of a site and a particular browser. Sessions allow you to save any amount of data per browser and make it available to the site anytime the browser connects. Individual session data items are then referred to by a &#8220;key,&#8221; which both saves and retrieves data.<\/p>\n<p>To identify each browser and its associated session with the site, Django employs a cookie with a unique session id. The real session data is stored by default in the site database (This is preferable to keeping the information in a cookie, which is more vulnerable to unwanted\/malicious users.). Django allows you to store session data in a variety of places (cache, files, &#8220;safe&#8221; cookies), but the default location is a smart and secure choice.<\/p>\n<h3>Prerequisites:<\/h3>\n<p>Complete all previous tutorial topics, including Django Views and Cookie Handling.<\/p>\n<h3>Django Session<\/h3>\n<p>Django recognises the importance of sessions on a website and hence it provides middleware and an inbuilt app that enables you to generate these session IDs quickly and easily.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Django-Session__1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83833\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Django-Session__1.png\" alt=\"Django Session\" width=\"868\" height=\"458\" \/><\/a><\/p>\n<p>\u201cdjango.contrib.sessions\u201d under Settings.py file, is an application that works on \u201cmiddleware.SessionMiddleware\u201d and is quite suitable to work with.<\/p>\n<p>The \u201cmiddleware.SessionMiddleware\u201d is held responsible for generating unique Session IDs. While \u201cdjango.contrib\u201d is also a helping hand when we are talking about storing our Sessions on the database.<\/p>\n<p>We can see the Django session table in the database when we migrate the application.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Django-Session__2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83834\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Django-Session__2.png\" alt=\"Django Session\" width=\"213\" height=\"237\" \/><\/a><\/p>\n<p>The django.contrib.sessions application is listed in the settings.py files under the INSTALLED APPS list.<\/p>\n<p>If you want to work on sessions, you&#8217;ll need to see if your browser supports cookies.<\/p>\n<p>Of course, you can check that in the settings, but let&#8217;s create some view functions and URLs to help you grasp the concepts better.<\/p>\n<p>The class backends.base.SessionBase acts as a base class for all session objects. It includes the following methods listed below.<\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Method<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">__getitem__(key)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s used to get the value of a session.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">__setitem__(key, value)<\/span><\/td>\n<td><span style=\"font-weight: 400\">Its purpose is to set the session value.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">__delitem__(key)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s used to delete session objects.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">__contains__(key)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It determines whether the container contains the particular session object.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400\">get(key, default=None)<\/span><\/td>\n<td><span style=\"font-weight: 400\">It&#8217;s used to retrieve the provided key&#8217;s session value.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Testing the Cookie-Saving Capability of the Browser<\/h3>\n<p>Paste the following code in the views.py file.<\/p>\n<p><strong>Code for cookie_session and cookie_delete:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def cookie_session(request):\n    request.session.set_test_cookie()\n    return HttpResponse(\"&lt;h1&gt;TechVidvan&lt;\/h1&gt;\")\n\n\ndef cookie_delete(request):\n    if request.session.test_cookie_worked():\n        request.session.delete_test_cookie()\n        response = HttpResponse(\"TechVidvan&lt;br&gt; This is your newly created cookie\")\n    else:\n        response = HttpResponse(\"TechVidvan &lt;br&gt; Sorry!! your browser does not accept cookies\")\n    return response\n<\/pre>\n<h4>set_test_cookie()<\/h4>\n<p>When your browser asks or sends a request for this webpage, we use this method to create a test cookie.<\/p>\n<h4>test_cookie_worked()<\/h4>\n<p>After the browser accepts the cookie, this method returns \u201cTrue\u201d as a boolean value. Otherwise, the statement is false.<\/p>\n<h4>delete_test_cookie()<\/h4>\n<p>The test cookie is deleted using this approach.<\/p>\n<p>Now, go to the urls.py file under the root project directory and add the following urls there.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">path('Testcookie',views.cookie_session),\npath('Deletecookie', views.cookie_delete),\n<\/pre>\n<p><strong>Output 1: Run the browser with \/Testcookie<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Cookie-saving__3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83837\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Cookie-saving__3.png\" alt=\"Django Cookie-saving\" width=\"1920\" height=\"452\" \/><\/a><\/p>\n<p><strong>Output 2: Now run the browser with \/Deletecookie<\/strong><\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Cookie-saving__4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83838\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Cookie-saving__4.png\" alt=\"Django Cookie-saving\" width=\"1920\" height=\"397\" \/><\/a><\/p>\n<p>If you see this message, your browser accepts cookies; otherwise, the browser will give you an unexpected response.<\/p>\n<p>If your results don&#8217;t look like the one above, make some changes that create your browser accepts cookies; otherwise, you won&#8217;t be able to use this tutorial.<\/p>\n<h3>Django Sessions: Creating and Using<\/h3>\n<p>Django makes it simple to create session variables and manipulate them.<\/p>\n<p>Django&#8217;s request object includes a session attribute that creates, accesses and modifies session variables. This attribute operates as a dictionary, allowing you to declare session names as keys and values.<\/p>\n<p><strong>1: First, we&#8217;ll change the views.py file.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def create_session(request):\n    request.session['Emp_name'] = 'Raghav'\n    request.session['Emp_Email'] = 'Raghav27@TechVidvan.com'\n    return HttpResponse(\"&lt;h1&gt;welcome to TechVidvan Employee Portal&lt;br&gt; The Session is Set&lt;\/h1&gt;\")\n\n\n\ndef access_session(request):\n    response = \"&lt;h1&gt;Welcome to Sessions of TechVidvan Employee Portal&lt;\/h1&gt;&lt;br&gt;\"\n    if request.session.get('Emp_name'):\n        response += \"Emp_Name : {0} &lt;br&gt;\".format(request.session.get('Emp_name'))\n    if request.session.get('Emp_Email'):\n        response += \"Emp_Email : {0} &lt;br&gt;\".format(request.session.get('Emp_Email'))\n        return HttpResponse(response)\n    else:\n        return redirect('create\/')\n<\/pre>\n<p><strong>2: In the urls.py file, add the following urls.<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">path('Create',views.create_session),\npath('Access',views.access_session),\n<\/pre>\n<p><strong>3: Execute the following code:<\/strong><\/p>\n<p>Search for \/Create<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Creating-and-using__3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83836\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Creating-and-using__3.png\" alt=\"Django Cookie Saving\" width=\"1897\" height=\"498\" \/><\/a><\/p>\n<p>Now search for \/Access<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Creating-and-using__4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83839\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Creating-and-using__4.png\" alt=\"Django Cookies and Sessions\" width=\"1920\" height=\"419\" \/><\/a><\/p>\n<p>The session_key and session_data with high encryption are visible in the database.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Creating-and-using__5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83840\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Creating-and-using__5.png\" alt=\"Django Creating and using sessions\" width=\"1888\" height=\"465\" \/><\/a><\/p>\n<p><strong>Understanding the Code:<\/strong><\/p>\n<p>The code is simple python, but the variables we use have some complicated python coding.<\/p>\n<p>If you request the Access\/ URL without first making the Create\/ request, you will be immediately redirected to the Create\/.<\/p>\n<p>When the Create\/ URL is delivered, the SessionsMiddleware executes and generates a unique SessionID, which is saved as a cookie for the user locally on the browser.<\/p>\n<p>This cookie, together with the request and sessions, is now delivered to the server every time. The application performs the task of matching the SessionID with a database entry.<\/p>\n<p>It also keeps track of the values and variables we set up in the create_session() view function.<\/p>\n<p>The request object has a session attribute, and when the server executes the code, the session middleware and the session\u2019s application operate together seamlessly.<\/p>\n<p>request.session[] acts like a python dictionary data structure, allowing you to store values alongside relevant keys.<\/p>\n<p>In the access_session() function, we used the get() in conjunction with request.session and gave the key&#8217;s value.<\/p>\n<p>As a result, you&#8217;ll have easy access to the sessions.<\/p>\n<p>There are numerous methods associated with the HttpRequest object&#8217;s session argument.<\/p>\n<h3>Deleting Django Sessions<\/h3>\n<p>You can probably remove the sessions after they have completed their tasks. Simply said, this view function should be included in the views.py file.<\/p>\n<p><strong>Code for delete_session:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">def delete_session(request):\n    try:\n        del request.session['Emp_name']\n        del request.session['Emp_Email']\n    except KeyError:\n        pass\n    return HttpResponse(\"&lt;h1&gt;TechVidvan&lt;br&gt;Session Data cleared&lt;\/h1&gt;\")\n<\/pre>\n<p>This code is also written in pure Python, using the concept of exception handling. We can use del to delete a session or a specific key within that session.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">del request.session[\u2018key_name\u2019]<\/pre>\n<p>To make this code work, add the following to the urlpatterns:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">path('Delete_sn', views.delete_session),<\/pre>\n<p>Don&#8217;t worry if your cookie isn&#8217;t deleted because we just use this way to erase your data in the Django database, not the session ID and cookie.<\/p>\n<p>Although sessions are deleted when the browser is closed, we use the flush() function to entirely erase session-related cookies.<\/p>\n<p>Let\u2019s have a look at Output:<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Deleting-Django__3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83841\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Deleting-Django__3.png\" alt=\"Django Delete Session\" width=\"1920\" height=\"340\" \/><\/a><\/p>\n<h3>Additional Actions Using Sessions<\/h3>\n<p>We&#8217;ve seen how to store and access a session, but it&#8217;s also worth noting that the request&#8217;s session attribute has various additional helpful actions, such as<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Actions \nWhat does it do?\nset_expiry (value):\nSets the session's expiration time.\n\n\nget_expiry_age():\nIt returns the number of seconds till the session expires \n\n\nget_expiry_date():\nIt is a function that returns the date when something has expired. \n\n\nclear_expired():\nHelps in removing expired sessions from the session store.\n\n\nget_expire_at_browser_close():\nIf the user's session cookies have expired when the user's web browser is closed, this method returns True or False.<\/pre>\n<h3>Session Timeout in Django<\/h3>\n<p>This is also one of the features which we can use while working with Django Sessions.<\/p>\n<p>Mention the code below in settings to timeout a Django session after a specific timestamp (in seconds).<br \/>\npy<\/p>\n<p>SESSION COOKIE AGE = 20 # for a time stamp of 20 seconds<\/p>\n<p>In the settings, specify the code below to timeout a Django session after a certain amount of time (in seconds) of inactivity.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">pip install django-session-timeout\n\nMIDDLEWARE = [\n    ...\n    'django_session_timeout.middleware.SessionTimeoutMiddleware',\n    ...\n    ]\n                                \n    SESSION_EXPIRE_SECONDS = 20\n    SESSION_EXPIRE_AFTER_LAST_ACTIVITY = True\n<\/pre>\n<h3>Configuration of the Django Session Engine<\/h3>\n<p>Session engines can be configured in a variety of ways. It&#8217;s a crucial decision because storage solutions can improve speed and response time.<\/p>\n<p>Django allows you to choose from these possibilities, but it does not limit your options. If you want to use a different storage technique, go to djangopackages.org.<\/p>\n<h4>1. Using a database Sessions<\/h4>\n<p>We&#8217;ve been using this way because we have the django.contrib.sessions application in our settings.py file&#8217;s under the INSTALLED APPS list.<\/p>\n<p>This is a typical implementation that covers a lot of security flaws. It also comes with several functionalities that you can use directly with Django&#8217;s view methods and models.<\/p>\n<h4>2. Through the use of cached sessions<\/h4>\n<p>You can utilise cache-based sessions to improve the performance of your website. You can use this space to practise a variety of techniques, such as setting up multiple caches.<\/p>\n<p>Django offers you additional session engines for this purpose:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">django.contrib.sessions.backends.cache<\/pre>\n<p>Data is directly stored in the cache by the above engine.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">django.contrib.sessions.backends.cache db<\/pre>\n<p>On the other hand, this engine is useful when you wish to use a write-through cache to save persistent sessions data with your server.<\/p>\n<p>Both strategies significantly boost your performance.<\/p>\n<h4>3. Using File-based Sessions<\/h4>\n<p>You can utilise Django&#8217;s engine to store your sessions data in a file-based system.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">django.contrib.sessions.backends.file<\/pre>\n<p>You&#8217;ll also need to make sure that your web server has permission to read and write the directory where your sessions file is stored.<\/p>\n<h4>4. Through the use of cookie-based sessions<\/h4>\n<p>We don&#8217;t recommend this one because sessions were designed to avoid storing data in cookies in the first place, but it&#8217;s still used by developers for whatever reason.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">django.contrib,sessions.backends.signed cookies<\/pre>\n<p>With the help of Django&#8217;s cryptographic signing tool and the secret key, your session data can be saved.<\/p>\n<p>It has all of the issues with cookies, the most serious of which is that session cookies are signed but not encrypted, allowing the client to access them. It also has performance difficulties because the request size is affected by the cookie size.<\/p>\n<h3>Summary:<\/h3>\n<p>Django provides some pretty intuitive methods for implementing sessions and interacting with them. It\u00a0includes several choices for making your web project as dynamic and fast-paced as you want it to be.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In our previous article, we covered Django Cookies. Let&#8217;s take it a step further and look at Session in Django. Let&#8217;s take a quick look at the concept of cookies and look at some&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":83827,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3383],"tags":[4059,4060],"class_list":["post-83717","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-django","tag-create-django-sessions","tag-django-session"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Django Session- Learn the Steps to Manage Sessions in Django - TechVidvan<\/title>\n<meta name=\"description\" content=\"Django &amp; most of the web framework use session to maintain track of the &quot;state&quot; of a site and a particular browser. Learn more about it.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/django-session\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Django Session- Learn the Steps to Manage Sessions in Django - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Django &amp; most of the web framework use session to maintain track of the &quot;state&quot; of a site and a particular browser. Learn more about it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/django-session\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-14T03:30:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Django-Session.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Django Session- Learn the Steps to Manage Sessions in Django - TechVidvan","description":"Django & most of the web framework use session to maintain track of the \"state\" of a site and a particular browser. Learn more about it.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/django-session\/","og_locale":"en_US","og_type":"article","og_title":"Django Session- Learn the Steps to Manage Sessions in Django - TechVidvan","og_description":"Django & most of the web framework use session to maintain track of the \"state\" of a site and a particular browser. Learn more about it.","og_url":"https:\/\/techvidvan.com\/tutorials\/django-session\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-08-14T03:30:08+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Django-Session.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/django-session\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-session\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Django Session- Learn the Steps to Manage Sessions in Django","datePublished":"2021-08-14T03:30:08+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-session\/"},"wordCount":1773,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-session\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Django-Session.jpg","keywords":["Create Django Sessions","Django Session"],"articleSection":["Django Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/django-session\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/django-session\/","url":"https:\/\/techvidvan.com\/tutorials\/django-session\/","name":"Django Session- Learn the Steps to Manage Sessions in Django - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-session\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-session\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Django-Session.jpg","datePublished":"2021-08-14T03:30:08+00:00","description":"Django & most of the web framework use session to maintain track of the \"state\" of a site and a particular browser. Learn more about it.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/django-session\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/django-session\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/django-session\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Django-Session.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Django-Session.jpg","width":1200,"height":628,"caption":"Django Session"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/django-session\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Django Session- Learn the Steps to Manage Sessions in Django"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83717","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=83717"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83717\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/83827"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=83717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=83717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=83717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}