First post to this group; I hope it's appropriate and has the necessary info. 
My goal is to set ["SESSION_FILE_DIR"] = 'C:/some/path' to a path where files 
uploaded via my app can be saved. Now my app is very large and so it is 
factored in a large collection of blueprints and I want the same settings to be 
applied globally across the application. That is, ["SESSION_FILE_DIR"] = 
'C:/some/path' would be the session path for any aspect of the program.

I am currently unable to make the desired path available in my blueprints; it 
is only available for routes contained within the main app. Below, for purposes 
of debugging, I've created a small example that prints the path to the screen. 
As an example, if you create this below and head over to the route 
.../print_dir the path is visible and I can actually save files to that 
location. However, if I head over to the registered blueprint path, .../new, I 
get the error the server is not defined.

What steps do I need to take so that the session path I want to save to is 
available in my blueprints?

Thank you


##################### Contents of my main app.py file
from flask import Flask, render_template, request, session
from flask_session import Session
import tempfile

server = Flask(__name__)

server.config["SESSION_PERMANENT"] = False
server.config["SESSION_TYPE"] = "filesystem"
server.config["SESSION_FILE_DIR"] = 'C:/some/path'
server.secret_key = 'abcdefg'

### Import and Register Blueprints 
from tools.routes import my_bp

server.register_blueprint(my_bp)

@server.route('/')
def homepage():
    return "Hello"

@server.route('/print_dir')
def homepage2():
    return server.config["SESSION_FILE_DIR"]

if __name__ == '__main__':
    server.run(debug=True)


############################ Contents of my routes.py file in a subdirectory 
called tools #############
from flask import Flask, render_template, request, session, Blueprint
from flask_session import Session

my_bp = Blueprint("my_bp", __name__)

@my_bp.route('/new', methods=['POST', 'GET'])
def path(): 
    path = server.config["SESSION_FILE_DIR"]
    return path
_______________________________________________
Web-SIG mailing list
Web-SIG@python.org
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: 
https://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com

Reply via email to