1

I have this flask code in an auth blueprint:

 @auth.route('/login/',methods=['POST','GET'])
 def login():
      email         = request.form.get('email',type=str)
      password      = request.form.get('password',type=str)

      error = None
      if email != None and password != None:
           if verify_user(email,password):
               user = next((item for item in app.config['AUTHORIZED'] if item["email"] == email), None)
               session['name'] = user['name']

               flash("welcome " + session['name'] + '!')
               return redirect(url_for('admin.show'))

           error = "invalid credentials" 

      return render_template('auth/index.html',error=error)

and the following in an admin blueprint, which I am redirecting to from the login:

 @admin.route('/admin/',methods=['GET'])
 def show():
     if not 'name' in session:
         return abort(403)
     return render_template('admin/index.html')

However, when I successfully login, flask merely prints the html from admin/index.html to the javascript console in both Chrome and Firefox.

2 Answers 2

2

Since you mention the JS console, you're presumably making this request via Ajax. So your Ajax handler needs to do any redirection.

Sign up to request clarification or add additional context in comments.

1 Comment

Can you give an example please? :)
0

When you are requesting your form data from html, make sure that your button has the type="submit" instead of type="button". Changing this fixed the issue for me.

<form class="form-logIn" action="/logIn" method="post">
  <label for="email" class="sr-only">Email address</label>
  <input type="email" name="email" id="email" class="form-control" placeholder="Email address" required autofocus>
  <label for="password" class="sr-only">Password</label>
  <input type="password" name="password" id="password" class="form-control" placeholder="Password" required>

  <button id="btnLogIn" class="btn btn-lg btn-secondary btn-block" type="submit">Log In</button>
</form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.