[Flask] Issues with Flash_session - Cannot add dict item ..
Ben Duncan
linux4ms at gmail.com
Wed Sep 25 10:02:04 EDT 2019
Thanks for all the help ...
Here is the code
session = Session()
print "Session type is --------", type(session)
session.init_app(app)
print "Session init type is --------", type(session)
print "Dir of session is:", dir(session)
session = {'modified': False }
As noted, from my earlier post, it looks like a dictionary needs to be
initialized with a dictionary.
Once I did this, all is well in never-never land
Local IT even fixed my borken desktop ...
😁
*Ben Duncan*
DBA / Chief Software Architect
Mississippi State Supreme Court
Electronic Filing Division
On Wed, Sep 25, 2019 at 7:51 AM Ziirish <ziirish at ziirish.info> wrote:
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20190925/09ae7743/attachment-0001.html>
More information about the Flask
mailing list