In my Python (3.5) Flask project, I am using the CAS client for authentication and everything works fine. Once the authentication is done, I want to display the username in my output page. So I use the following code
__init__.py:
from flask import Flask
from flask_cas import CAS
from flask_cas import login_required
# ...
APP = Flask(__name__)
cas = CAS(APP)
# ...
def list_page()
return render_template("list.html", name=cas.username)
@app.route('/admin/')
@login_required
def admin_page()
return list_page();
list.html:
...
<H2> Hi {{name}} </h2>
...
At the output page I am seeing
Hi <property object at 0x7fb37dfe6958>
It's hard to pinpoint exactly what the problem is without knowing what your cas variable is, in __init__.py. However I suspect the error you have might be because cas is a class, rather than an instance of that class.
To show you what I mean:
>>> class MyCAS:
... @property
... def name(self):
... return 'Monjur'
...
>>> MyCAS.name
<property object at 0x109cf1cc8>
>>> MyCAS().name
'Monjur'
In the first case, I have not instantiated the class (no parenthesis), so the return value is the property object. In the second case (with parenthesis), I see the actual name of the instance.
If your cas object is indeed supposed to be an object instantiated from a class (e.g. flask.ext.cas.CAS), make sure you create it like this:
from flask.ext.cas import CAS
cas = CAS() # With parenthesis :)
and not like this:
from flask.ext.cas import CAS
cas = CAS # No parenthesis :(
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With