[Flask] Issues with Flash_session - Cannot add dict item ..

Ziirish ziirish at ziirish.info
Wed Sep 25 08:51:16 EDT 2019


Here is your problem:

from flask import session
session = Session()

The flask session object is not a Flask-Session Session object.

What you want instead is:


sess = Session()
sess.init_app(app)

Then you can do:

session['modified'] = False  # here session is the Flask's session object


* On Wednesday, September 25, 2019 at 06:55 AM -0500, Ben Duncan <linux4ms at gmail.com> wrote:
> Doing a dir on the Session defined in flask-session shows everything loaded.
> I'm not sure, but I did this in the view after all the session stuff:
> 
> session{'status': 'GOOD'}
> 
> And another dir after this show the original stuff in there with a bunch of
> new classes added.
> Could be that a user dictionary isn't established unless you initiate it ...
> 
> I'd send the code samples, but alas OUR IT department has screwed up my
> local connection to our VM's.... sigh ...
> 
> *Ben Duncan*
> DBA / Chief Software Architect
> Mississippi State Supreme Court
> Electronic Filing Division
> 
> 
> On Tue, Sep 24, 2019 at 1:12 PM Gergely Polonkai <gergely at polonkai.eu>
> wrote:
> 
> > My first thought, without actual code to look at, is that you import
> > session from flask globally, but you also create a session variable
> > somewhere which is an instance of flask_session.Session.
> >
> > Can this be your culprit? Or are you positive that the session variable
> > you use is the same as the one you create?
> >
> > Best,
> > Gergely
> >
> > On Tue, 24 Sep 2019, 17:15 Ben Duncan, <linux4ms at gmail.com> wrote:
> >
> >> Ok, am i missing something ?
> >>
> >> View:
> >>
> >> from flask import Flask, render_template, request, redirect, url_for,
> >> flash, make_response, escape, g
> >> from flask_session import Session
> >> from flask_sqlalchemy import SQLAlchemy
> >> from flask import session
> >>  .....
> >>
> >> app = Flask(__name__)
> >> print 'APP is : ', app
> >> csrf = CSRFProtect(app)
> >>
> >> session = Session()
> >> session.init_app(app)
> >>
> >> When I try to do something like this:
> >>
> >> session['modified'] = False
> >>
> >> I get :
> >>
> >>    - e
> >>    "/opt/rh/python27/root/usr/lib64/python2.7/site-packages/flask/app.py",
> >>    line *1935*, in dispatch_request
> >>
> >>    return self.view_functions[rule.endpoint](**req.view_args)
> >>
> >>    - File "/data/flask/applications/myproject/wtform.py", line *334*, in
> >>    contact
> >>
> >>    session['modified'] = False
> >>
> >>
> >> TypeError: 'Session' object does not support item assignment
> >>
> >> What Am I doing wrong .... ?
> >>
> >>
> >> *Ben Duncan*
> >> DBA / Chief Software Architect
> >> Mississippi State Supreme Court
> >> Electronic Filing Division


More information about the Flask mailing list