Django Session across apps - django

request.COOKIES.get("myapp_sessionid")
how above code line can be used to get session values across apps?
I want to share session values across django apps in same django project.
But session values get cleared in new second app.

Related

Resetting django_sessions

I was playing around with storing session ids for anonymous users in django models using django.contrib.sessions.models and tested all browsers on my machine creating different keys sometimes based on the real and incognito sessions.
I followed it up by deleting my database and creating a new one as part of my tests and development emptying out all tables.
I am noticing now that when I revisit the site from the same computer/browser, django does NOT create and store a new session id even though the table is empty which means that the server is storing the information that I previously visited the site as an anon user somewhere other than the django_sessions table.
I tested clearing out my cookies and history but that did not help. Does anyone know where that information is stored, why, and how can I reset it? This is an issue mainly because I am using the session id as foreignkey and if i do end up deleting the database after deployment for any reason, i dont want the program to not work properly.
Using python 3.8 and django 3.0.2
Thanks.

React + Django app refreshes for every deletion in Django admin panel

I'm not really sure what to share (i.e. which part of my application code) as I'm still a beginner with React so please bear with me.
I have a React application running on top of a Django application. Basically, there are Django Admin Panel URLS, REST API URLS in Django, and one path to catch all paths that don't belong to the first two groups.
I have a page (or a React Container) that calls Django's REST API to query all entries in the users DB Table. This part is okay but what I've noticed is, everytime I manually delete a row in the Django Admin Panel, the whole page refreshes. What are possible reasons for this?
By the way, I'm using Redux as well to manage the whole application state.

Django: Saving oauth provider data

I set up a simple django site using django-allauth.
I created some oauth providers in the database.
Everything is fine and working on my laptop now.
I would like to store the created database tables somehow.
Use case: I want to set up a new development environments on a different PC painlessly.
How to store the initial data of django_allauth, so that after checking out the app from git the command manage.py migrate is all I need to have the relevant database tables filled?
Django_allauth already save those data to the database, you will find them in a table *_SocialApp, here is the model code from django_auth source

Django Session with Memcached or ElastiCache, does the Django code need to be changed?

I have an app using DB as session backend, and I realize that Django allows a Memcached-like (memcached, ElastiCache) session backend.
Reading the doc at Django site, I found the setting file can specify that change. My question is whether my view logic code files need any change.
No. You shouldn't have to change anything. If you deploy the code on a live site, active sessions will be lost (all users will be logged out).

Django site framework: How to manage access to different sites sharing same database?

I have two Django sites that share the same database and some functionnalities. Each site has its own settings.py with a different SITE_ID. Each site is running under its own runserver process.
I have this custom backend that check if user is allowed to access the current site during login:
user_or_none = super(SiteBackend, self).authenticate(**credentials)
if user_or_none and user_or_none.get_profile().sites.filter(id=Site.objects.get_current().id).count() < 1:
user_or_none = None
A user can access a site if SITE_ID is stored in his profile (in auth_user_profile_site table)
My problem is that when a user is logged in one of the site he has access, he can then switch to the other site that he does not have access and system let him enter.
Also, once logged in one site, It seems that when switching to the other site, SITE_ID obtained from: Site.objects.get_current().id does not corespond to this second site ID, we always receive the SITE_ID from the first site logged in...
Is it normal behaviour of the site framework?
Any suggestion how to solve those problems?
Thanks a lot
Etienne
You should look for answers in django session framework. When someone logins it saves user id in session. And session is just a temporary storage (you can acces it in view request.session). Depend on session backend, it can interact with that other site.
Look here