Question

I am new to flask and I am trying to use flask-login to manage user authentication in my application along with Google plus sign in. I using flask.ext.login in my application but it shows me

ImportError: No Module named flask.ext.login

Here is my views.py file

from google.appengine.api import users
from google.appengine.runtime.apiproxy_errors import CapabilityDisabledError


from flask import request, render_template, flash, url_for, redirect
from flask.ext.login import current_user
import flask,flask.views
from flask_cache import Cache

from application import app
from decorators import login_required, admin_required
from forms import ExampleForm
from models import ExampleModel

class View(flask.views.MethodView):
    def get(self):
        # check if the user is logged in or not
        if not login.current_user.is_authenticated():
            return app.login_manager.unauthorized()
        return flask.render_template('index.html')




class Login(flask.views.MethodView):
    def get(self):
        return None

    def post(self):
        # Create a state token to prevent request forgery.
        # Store it in the session for later validation.
        state = ''.join(random.choice(string.ascii_uppercase + string.digits)
              for x in xrange(32))
        session['state'] = state
        # Set the Client ID, Token State, and Application Name in the HTML while
        # serving it.
        response = make_response(render_template('index.html',CLIENT_ID='1075048200759- 5hunu03e087bha87d48874veh1rvr97f.apps.googleusercontent.com', STATE=state, APPLICATION_NAME='uscore_signin'))
        response.headers['Content-Type']='text/html'
        return response, session

Could you please suggest me How to fix it , am I using the importing hierarchy in the wrong way even I followed the previous discussion New to flask and Flask-Login - ImportError: No module named login

Was it helpful?

Solution

If following does not work:

from flask.ext.login import current_user

try the following:

from flask_login import current_user

This is the new convention.

To find the flask-login version, you can run the following command in terminal. Just change the name to know the version of other packages.

pip show flask-login
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top