how to persist user info in session flask-securityHow to get data received in Flask requestHow do you get a query string on Flask?Python: Flask-security, register does not persist userHow to serve static files in FlaskShare sqlalchemy models between flask and other appsFlask-SQLAlchemy - how do sessions work with multiple databases?How to avoid hard-coding database path using flask, SQLAlchemy, and declarative_basepython venv setup ModuleNotFoundError: No module named 'sqlalchemy' despite verifying it is available in virtual environmentflask socket io not working ( windows 7 & 10 ) anaconda and python 3.7

What's the point of having a RAID 1 configuration over incremental backups to a secondary drive?

The three greedy pirates

GDPR rights when subject dies; does family inherit subject rights?

When I press the space bar it deletes the letters in front of it

Matrix with arrows and comments

LED glows slightly during soldering

Addressing unnecessary daily meetings with manager?

Write a function

How do we handle pauses in a dialogue?

Why did Harry Potter get a bedroom?

Is a request to book a business flight ticket for a graduate student an unreasonable one?

How to tell someone I'd like to become friends without letting them think I'm romantically interested in them?

Did the Ottoman empire suppress the printing press?

How do native German speakers usually express skepticism (using even) about a premise?

What attributes and how big would a sea creature(s) need to be able to tow a ship?

Graduate student with abysmal English writing skills, how to help

What is the minimum time required for final wash in film development?

Is there a strong legal guarantee that the U.S. can give to another country that it won't attack them?

Is it possible to split a vertex?

How to design a CMC (Common Mode Choke) footprint to allow no-pop solution

A horrible Stockfish chess engine evaluation

What happens to unproductive professors?

Having decision making power over someone's assets

Misspelling my name on my mathematical publications



how to persist user info in session flask-security


How to get data received in Flask requestHow do you get a query string on Flask?Python: Flask-security, register does not persist userHow to serve static files in FlaskShare sqlalchemy models between flask and other appsFlask-SQLAlchemy - how do sessions work with multiple databases?How to avoid hard-coding database path using flask, SQLAlchemy, and declarative_basepython venv setup ModuleNotFoundError: No module named 'sqlalchemy' despite verifying it is available in virtual environmentflask socket io not working ( windows 7 & 10 ) anaconda and python 3.7






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I'm working on a flask app which uses flask-security to manage access. I noticed from the sqlalchemy echo that for every endpoint decorated by @roles_accepted, it send a new query to the database (too many repeated requests). Is this behavior expected for flask-security? Is there any way to persist the user info within session to reduce the number of query requests?



@roles_accepted('admin')
def index():
...
return render_template('main.html')


I found in here an example for sqlalchemy session. I'm new to Flask, so I don't quite understand is this the same as the user session in the browser? If so, how do I integrate this to my app? I'm confused by how database.py works in the example. Any help is appreciated!



my db is initiated using create_app(), do I need to create a new session in this case? Or how do I use the db instance in create_app in the example?



db = SQLAlchemy()

def create_app()
...
db.init_app(app)


https://pythonhosted.org/Flask-Security/quickstart.html



database.py



from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('sqlite:////tmp/test.db',
convert_unicode=True)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base()
Base.query = db_session.query_property()

def init_db():
# import all modules here that might define models so that
# they will be registered properly on the metadata. Otherwise
# you will have to import them first before calling init_db()
import models
Base.metadata.create_all(bind=engine)









share|improve this question






























    0















    I'm working on a flask app which uses flask-security to manage access. I noticed from the sqlalchemy echo that for every endpoint decorated by @roles_accepted, it send a new query to the database (too many repeated requests). Is this behavior expected for flask-security? Is there any way to persist the user info within session to reduce the number of query requests?



    @roles_accepted('admin')
    def index():
    ...
    return render_template('main.html')


    I found in here an example for sqlalchemy session. I'm new to Flask, so I don't quite understand is this the same as the user session in the browser? If so, how do I integrate this to my app? I'm confused by how database.py works in the example. Any help is appreciated!



    my db is initiated using create_app(), do I need to create a new session in this case? Or how do I use the db instance in create_app in the example?



    db = SQLAlchemy()

    def create_app()
    ...
    db.init_app(app)


    https://pythonhosted.org/Flask-Security/quickstart.html



    database.py



    from sqlalchemy import create_engine
    from sqlalchemy.orm import scoped_session, sessionmaker
    from sqlalchemy.ext.declarative import declarative_base

    engine = create_engine('sqlite:////tmp/test.db',
    convert_unicode=True)
    db_session = scoped_session(sessionmaker(autocommit=False,
    autoflush=False,
    bind=engine))
    Base = declarative_base()
    Base.query = db_session.query_property()

    def init_db():
    # import all modules here that might define models so that
    # they will be registered properly on the metadata. Otherwise
    # you will have to import them first before calling init_db()
    import models
    Base.metadata.create_all(bind=engine)









    share|improve this question


























      0












      0








      0








      I'm working on a flask app which uses flask-security to manage access. I noticed from the sqlalchemy echo that for every endpoint decorated by @roles_accepted, it send a new query to the database (too many repeated requests). Is this behavior expected for flask-security? Is there any way to persist the user info within session to reduce the number of query requests?



      @roles_accepted('admin')
      def index():
      ...
      return render_template('main.html')


      I found in here an example for sqlalchemy session. I'm new to Flask, so I don't quite understand is this the same as the user session in the browser? If so, how do I integrate this to my app? I'm confused by how database.py works in the example. Any help is appreciated!



      my db is initiated using create_app(), do I need to create a new session in this case? Or how do I use the db instance in create_app in the example?



      db = SQLAlchemy()

      def create_app()
      ...
      db.init_app(app)


      https://pythonhosted.org/Flask-Security/quickstart.html



      database.py



      from sqlalchemy import create_engine
      from sqlalchemy.orm import scoped_session, sessionmaker
      from sqlalchemy.ext.declarative import declarative_base

      engine = create_engine('sqlite:////tmp/test.db',
      convert_unicode=True)
      db_session = scoped_session(sessionmaker(autocommit=False,
      autoflush=False,
      bind=engine))
      Base = declarative_base()
      Base.query = db_session.query_property()

      def init_db():
      # import all modules here that might define models so that
      # they will be registered properly on the metadata. Otherwise
      # you will have to import them first before calling init_db()
      import models
      Base.metadata.create_all(bind=engine)









      share|improve this question
















      I'm working on a flask app which uses flask-security to manage access. I noticed from the sqlalchemy echo that for every endpoint decorated by @roles_accepted, it send a new query to the database (too many repeated requests). Is this behavior expected for flask-security? Is there any way to persist the user info within session to reduce the number of query requests?



      @roles_accepted('admin')
      def index():
      ...
      return render_template('main.html')


      I found in here an example for sqlalchemy session. I'm new to Flask, so I don't quite understand is this the same as the user session in the browser? If so, how do I integrate this to my app? I'm confused by how database.py works in the example. Any help is appreciated!



      my db is initiated using create_app(), do I need to create a new session in this case? Or how do I use the db instance in create_app in the example?



      db = SQLAlchemy()

      def create_app()
      ...
      db.init_app(app)


      https://pythonhosted.org/Flask-Security/quickstart.html



      database.py



      from sqlalchemy import create_engine
      from sqlalchemy.orm import scoped_session, sessionmaker
      from sqlalchemy.ext.declarative import declarative_base

      engine = create_engine('sqlite:////tmp/test.db',
      convert_unicode=True)
      db_session = scoped_session(sessionmaker(autocommit=False,
      autoflush=False,
      bind=engine))
      Base = declarative_base()
      Base.query = db_session.query_property()

      def init_db():
      # import all modules here that might define models so that
      # they will be registered properly on the metadata. Otherwise
      # you will have to import them first before calling init_db()
      import models
      Base.metadata.create_all(bind=engine)






      python flask flask-security flask-session






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 26 at 0:59







      qshng

















      asked Mar 26 at 0:35









      qshngqshng

      3903 silver badges20 bronze badges




      3903 silver badges20 bronze badges






















          0






          active

          oldest

          votes










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348282%2fhow-to-persist-user-info-in-session-flask-security%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348282%2fhow-to-persist-user-info-in-session-flask-security%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현