I am trying to develop a Python app that uses flask with blueprint, and some of these "applications/forms" will need to login to CAS. We have CAS working - that's not the problem here.
My file/folder structure is as follows:
~/.
app.py
|
-> aaaForms
|
-> FForm
|
FormF.py
This is the contents of my app.py script:
import flask
from flask import Flask, render_template
#Importing blueprint into app.py as a reference, follows director structure to python file.
from aaaForms.FForm.FormF import FormF_blueprint
app = Flask(__name__)
app.register_blueprint(Ferpa_blueprint, url_prefix='/aaaForms/FForm')
app.secret_key = 'xUhhLjZktPTiDPTn7SSpoIb6EsHVE0'
if __name__ == "__main__":
app.run(debug=True)
This is my FormF.py script:
from flask import Flask, Blueprint, render_template
from flask_cas import CAS
from flask_cas import login_required
FormF_blueprint = Blueprint('FormF_blueprint',__name__, static_url_path='', static_folder='web/source', template_folder='web/templates')
FormF = Flask(__name__,
static_url_path='',
static_folder='web/source',
template_folder='web/templates')
cas = CAS(FormF, '/cas')
FormF.config['CAS_SERVER'] = 'https://mycastestserver.domain.com:8443'
FormF.config['CAS_AFTER_LOGIN'] = 'FormF_root'
@FormF_blueprint.route('/')
@login_required
def FormF_root():
print(cas.username)
username = cas.username
print(cas.attributes['cas:displayName'])
display_name = cas.attributes['cas:displayName']
return render_template('index.html', username=username, display_name=display_name)
Again, while I am trying to create a "blueprint" structure for around 50-60 apps/forms, only one or two will actually need CAS. So the CAS call is "embedded" within the app/form that requires its use.
When running this code, however, I always receive an error about the CAS URL not being able to be created/found (which I believe comes from the line "FormF.config['CAS_AFTER_LOGIN'] = 'FormF_root'", which I assume is because of the Blueprint structure, but no amount of editing that URL snippet will get me out of error
I've found little to no information on setting up flask Blueprint along with CAS. One or the other - but not both. I've had no issues using just one or the other (Blueprint/CAS), but can't seem to mix them.
What I want to achieve is only ONE port being used by flask for all of these various apps/forms, instead of each one having it's own port. So am I just using the wrong tools here, or is there some other secret I'm not aware of, and can't seem to find?