Django Session storage Redis Environment configuration

Source: Internet
Author: User
Tags install django pip install django

First step: Add the middleware in the settings.py in the project directory middleware:
# Session Middleware Django project is enabled by default session
' Django.contrib.sessions.middleware.SessionMiddleware ',

The second step: saving the session in Redis requires the introduction of a third-party extension, which we can use Django-redis to solve.
Install extensions
Pip Install Django-redis

Step three: Make the following settings in the settings.py file
# Redis Cache Configuration
CACHES = {
"Default": {
"Backend": "Django_redis.cache.RedisCache",
"Location": "REDIS://127.0.0.1:6379/1", # indicates a database with Redis number 1th
"OPTIONS": {
"Client_class": "Django_redis.client.DefaultClient",
}
},
"Session": {
"Backend": "Django_redis.cache.RedisCache",
"Location": "REDIS://127.0.0.1:6379/2", # indicates a database with Redis number 1th
"OPTIONS": {
"Client_class": "Django_redis.client.DefaultClient",
}
}
}
# The storage method used by the session
Session_engine = "Django.contrib.sessions.backends.cache"
# indicates which library to use to save session data
Session_cache_alias = "Session"

Django Session storage Redis Environment configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.