logo
  • Home
  • About
  • Contact Us

Checking if the Session exists in Django [Simple Method]

  • Said Py
  • February 03, 2020

Today we'll learn how to check if a session is exists in django.

syntax

1
if session_key in request.session:

example:

So we have already a session, this session has 'test' as a key and we want to check if this session exists.

code:

1
2
if 'test' in request.session:
   print('yes!')

output

1
yes!

Related posts

Creating and getting a session in Django

Setting the Expiration Time of the Session set_expiry()

Search

    Categories

    • Django Snippet
    • Django Tutorial
    • Python
    • Python Libraries
    • Python Tutorial
    • Questions And Answers

    Recent Posts

    Python-Pillow: How to Show an image in Python

    May 08, 2022

    Python-Pillow: How to get Image Filename, Size, Format, and Mode

    May 05, 2022

    Pillow: Installation and getting started (Python)

    April 29, 2022

    How to insert .format multiple variables in Python

    April 27, 2022

    How to put variable in regex pattern in Python

    April 20, 2022

    How to use Django JsonResponse with example

    April 16, 2022

    Tags

    • python
    • pillow
    • variable
    • django
    • http
    • string
    • loop
    • tuple
    • list
    • BeautifulSoup

    Our Links

    • Home
    • About us
    • Privacy policy

    Our Works

    • Tutorials
    • Examples
    • Snippets
    • Solutions

    Social Media

    About Pytutorial

    Python and Django Tutorials Blog