Intro to Flask-Login

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ม.ค. 2025

ความคิดเห็น • 109

  • @prettyprinted
    @prettyprinted  4 ปีที่แล้ว +2

    Join my free course on the basics of Flask-SQLAlchemy: prettyprinted.com/flasksql

    • @najeebpasha4794
      @najeebpasha4794 4 ปีที่แล้ว

      why @login_maneger.user_loader not working now

    • @calebalfred7061
      @calebalfred7061 3 ปีที่แล้ว

      sorry to be so offtopic but does anybody know of a method to get back into an instagram account..?
      I was stupid forgot the login password. I would love any assistance you can offer me.

    • @oakleyshiloh9755
      @oakleyshiloh9755 3 ปีที่แล้ว

      @Caleb Alfred instablaster ;)

    • @calebalfred7061
      @calebalfred7061 3 ปีที่แล้ว

      @Oakley Shiloh I really appreciate your reply. I found the site through google and im trying it out now.
      I see it takes a while so I will get back to you later when my account password hopefully is recovered.

    • @calebalfred7061
      @calebalfred7061 3 ปีที่แล้ว

      @Oakley Shiloh It did the trick and I actually got access to my account again. I'm so happy!
      Thank you so much, you saved my account :D

  • @misterclinical
    @misterclinical 5 ปีที่แล้ว +23

    This channel is priceless.

    • @prettyprinted
      @prettyprinted  5 ปีที่แล้ว

      I'm glad you like my channel! Thanks for watching.

  • @OverwhelmingGrace
    @OverwhelmingGrace ปีที่แล้ว

    I really like your tutorials. I have worked with sql databases for over 20 years and normally don't use sqlalchemy. It is a good program but it is easier for me to use sql. I know you can execute sql from sqlalchemy, but why bother if you don't use the rest of the features? I usually start by creating a class for each table and use sql to do crud operations. Most tutorials for flask-login are 80% sqlalchemy and building an entire authorization system. I already have that. All I needed was the login/logout & session information. Yours is the only tutorial I saw that did not spend most of the time building an entire auth system. As always, your video was short, to the point, and easy to follow.

  • @worthaglimpse
    @worthaglimpse 3 ปีที่แล้ว

    your flask tutorials are lit bro . thanks a lot

  • @brunodiaz6100
    @brunodiaz6100 5 ปีที่แล้ว

    your type speed is incredible. good video!

  • @vinnnnnny12345
    @vinnnnnny12345 7 ปีที่แล้ว +1

    im stuck at 6:37. my application is call finalProject and i run from finalProject import db but got the error:
    ImportError: No module named flask_login
    any help would be appreciated

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว +2

      Did you install flask login using pip?
      pip install flask-login

    • @vinnnnnny12345
      @vinnnnnny12345 7 ปีที่แล้ว

      Pretty Printed yes, what was wrong was that I needed to get the latest version of pip

  • @findpatterns
    @findpatterns 8 ปีที่แล้ว +5

    Thanks. really high quality video.

  • @RuanBekker
    @RuanBekker 8 ปีที่แล้ว +9

    awesome, as always!

  • @luno_b5312
    @luno_b5312 8 ปีที่แล้ว +1

    Awesome :) I've noticed that django does a lot of things automatically vs flask... Flask is the perfect starting point as you will understand more of the hidden django operations :) well explained video 👍

    • @danieldaschle
      @danieldaschle 8 ปีที่แล้ว +1

      yes, me to. but django is a full stack framework and flask only a minimalist. i would be great if flask has the same database skill :)

    • @luno_b5312
      @luno_b5312 8 ปีที่แล้ว

      Yeah agree:) I really do like django:)

    • @danieldaschle
      @danieldaschle 8 ปีที่แล้ว

      i tested it yesterday, firstly i think it is better than flask. but with flask classy and other extension it is way easier...

    • @luno_b5312
      @luno_b5312 8 ปีที่แล้ว

      Oh yeah I agree:) django is awesome, the built in functionality is awesome (admin, database and validation functionality)

    • @danieldaschle
      @danieldaschle 8 ปีที่แล้ว

      i prefer flask now. i saw SQLAlchemy and many other which are very good! :D

  • @looploop6612
    @looploop6612 4 ปีที่แล้ว +1

    what is "load_user" used for?
    you declared but did not use it

  • @ezekielchoke2580
    @ezekielchoke2580 7 ปีที่แล้ว +1

    Thanks for an amazing video. Do you think Flask Login (alongside with Flask-security) can be used with Flask Blueprints? What I'm concerned about is is there a way how to define the User and the db outside of the app.py file, so that everything is a bit more neatly organized?

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว +1

      Yes, you can. Regardless of how you organize your app, you'll be able to use Flask-Login.

    • @ezekielchoke2580
      @ezekielchoke2580 7 ปีที่แล้ว

      Thans for the answer. However, I constantly run into ImportErrors when using Flask-security in combination with Blueprints, so I decided to go a different way. Thanks anyway!

  • @estebanmejia9989
    @estebanmejia9989 4 ปีที่แล้ว +1

    How can i avoid the access to a url from my site in reactjs using an api with this login?

  • @charlesmoses4730
    @charlesmoses4730 5 ปีที่แล้ว +4

    the link for the code takes me to a site with a 404 error

    • @Julian-tf8nj
      @Julian-tf8nj 4 ปีที่แล้ว

      A year later, it STILL gives a 404 error... apparently, no longer maintained :/

  • @peterjohnson6439
    @peterjohnson6439 6 ปีที่แล้ว

    In the video, and I am not sure if you will address this in further videos yet, when you are calling a list of users for the usernames what do you do in that case? Is there a video that covers pulling names from this list rather than just the one name? Or do you have to list each of the usernames?

    • @prettyprinted
      @prettyprinted  6 ปีที่แล้ว

      I'm not sure what you mean. Why would you want to use a list of users for login functionality. it should only be one user at a time.

  • @martiny1785
    @martiny1785 4 ปีที่แล้ว

    How is user_id in the load_user function not equal to none?? Because when i put the int() before the user_id it gives me a ValueError invalid literal for int() with base 10: 'None''

  • @shivamkapoor1827
    @shivamkapoor1827 5 ปีที่แล้ว +1

    I cant understand the pourpose of @login_manager.user_loader please make me understand

    • @prettyprinted
      @prettyprinted  5 ปีที่แล้ว +2

      Flask-Login stores the user ID in a cookie. When it reads that cookie, it takes the user ID and calls the query in the user_loader to find the user associated with that cookie.

  • @sagarpanwar69
    @sagarpanwar69 4 ปีที่แล้ว

    what if i have a environment databse url , then what to use in plde of db.model in user class

  • @Rapidodalua2008
    @Rapidodalua2008 7 ปีที่แล้ว

    Is it possible to create a Playlist for all your Flask-Login related stuff? And how should we follow up, it would be much appreciated!

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว

      I'm thinking of ways to make the playlists more organized here. There are limits to TH-cam playlists, so I may have to put together something on my website.

  • @randyhorsey
    @randyhorsey ปีที่แล้ว

    Great video! Thank you

  • @dennisasamoah2213
    @dennisasamoah2213 4 ปีที่แล้ว

    please how do i use the flask login without sqlAlchemy , but with the the traditional database ;
    HELP ME

  • @Kevinschart
    @Kevinschart 7 ปีที่แล้ว

    In your tutorials you put a lot of code in the flask views file. In a more production ready app would most of the computation be done by functions saved in a separate module?

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว

      Yeah, it's easier to have all the code in one file for my TH-cam videos. For production apps, you'd be better off separating them if you have a lot of code. I have a video on one way to do it here: th-cam.com/video/_5OXmXvkU_E/w-d-xo.html
      There are plenty of other ways to do it though.

  • @chewanggyaltsenbhutia2407
    @chewanggyaltsenbhutia2407 5 ปีที่แล้ว +1

    Thank you ,for the awesome tutorial .

  • @aldomatus6007
    @aldomatus6007 3 ปีที่แล้ว

    Wow you are amazing! Thanks for your videos, You really help me

  • @unknown-mk8sf
    @unknown-mk8sf 5 ปีที่แล้ว +1

    great tutorial! thanks you sir

  • @sol-ce7ct
    @sol-ce7ct 6 ปีที่แล้ว +2

    great tutorial, but how about having captions? hard to follow - bit fast :(

  • @HimanshuBansal2089
    @HimanshuBansal2089 7 ปีที่แล้ว

    Great tutorial, My only question is there a cleaner way to apply 'login_required' on multiple methods or i have to decorate every method that requires user login??

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว

      Yes, you can use class-based views and then apply the decorator once in the class. See here: flask.pocoo.org/docs/0.12/views/

    • @HimanshuBansal2089
      @HimanshuBansal2089 7 ปีที่แล้ว

      thanks for the solution, i have been searching this for long time

  • @espenkl
    @espenkl 6 ปีที่แล้ว

    Hi, great video. One question, does Flask-Login make the session secure? Or what to add to make the session secure? If i use a form, is it then to apply Csrf protection to the form?

    • @prettyprinted
      @prettyprinted  6 ปีที่แล้ว

      The session is secure, but the CSRF token is something different. You'll have to add that to the form yourself.

  • @borbagui
    @borbagui 8 ปีที่แล้ว +1

    Nice tutorial, congrats!!!

  • @yhhsteven
    @yhhsteven 7 ปีที่แล้ว

    What was the program you used for running Python script, the orange icon one?

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว

      It's Bash on Windows so you can use Ubuntu inside of Windows.

  • @mayurpande5415
    @mayurpande5415 7 ปีที่แล้ว

    I have an external database that I am connected through pypyodcs, would I need to still need to make a user class in the same way you have, as all I want to do is check if the user is logged in, if they are get them to enter there credentials and check against the mssql database.

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว

      Yeah, you'll need a user class and a user loader. This is so Flask-Login can map sessions to actual users in your database. It doesn't have to be like a SQLAlchemy class though, where it has all the table information.

    • @mayurpande5415
      @mayurpande5415 7 ปีที่แล้ว

      ah ok think I got you. So you mean within my user class, I can use a try-except to connect to my mssql db using pypyodbc connector, then from there I can use those credentials to check if the user is logged in or not, am I on the right track? Also is there a way to obtain the user details if logged in, as I need to pass the user details in a post request to an api. Thanks for the help

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว

      You don't necessarily need to connect to your database using the user class directly. The user class should just represent a user. The user loader should be a little more direct to your database though, so you can query the database for a particular user given an ID.

    • @mayurpande5415
      @mayurpande5415 7 ปีที่แล้ว

      Ok can I use the email address as an id? As I don't have any other id in the user table, well there is but it is a crazy long hexnumber I think! I didn't create the table! I'm still a noob, the head developer at my work did

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว +1

      Yeah, an email address is fine as an ID. The ID just has to be unique.

  • @kashifkhan-il4ne
    @kashifkhan-il4ne 5 ปีที่แล้ว +1

    please do a tutorial on flask-login with mongodb

  • @sahanabadri5877
    @sahanabadri5877 6 ปีที่แล้ว

    How to use Flask-login using pymongo? Do you have any videos on it?

    • @prettyprinted
      @prettyprinted  6 ปีที่แล้ว

      You'll have to write query in the user load to get your user with pymongo. I don't have any videos on it, but perhaps I'll create one.

  • @slinbody
    @slinbody 7 ปีที่แล้ว

    How can I handle the "Unauthorized" Page by myself ? For example, I want to custom the words. Thank you.

    • @slinbody
      @slinbody 7 ปีที่แล้ว

      login_manager.unauthorized_handler

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว

      USER_UNAUTHENTICATED_ENDPOINT configuration value.

  • @jasper5016
    @jasper5016 6 ปีที่แล้ว

    Is it doing anything other than session handling? I dont find flask-login very useful.

    • @prettyprinted
      @prettyprinted  6 ปีที่แล้ว

      Just session handling. Check out Flask-User or Flask-Security if you want more.

  • @shivamkapoor1827
    @shivamkapoor1827 5 ปีที่แล้ว

    If we not inharrit from usermixin then we can use login_user (user) and logout_user () function or not?

    • @prettyprinted
      @prettyprinted  5 ปีที่แล้ว

      The UserMixin makes it easy for Flask Login to know what represents a user. If you don't have that then you'll need to create your own methods so you can use login_user.

  • @piyushvikasduta
    @piyushvikasduta 3 ปีที่แล้ว

    How to customise and put `username` instead of `id` in get_id() method inside flask_login

  • @docetes
    @docetes 8 ปีที่แล้ว

    love the vids! When is the next one due out :)

    • @prettyprinted
      @prettyprinted  8 ปีที่แล้ว

      Thanks!
      i plan on recording the next video today. I lost my voice last week.

  • @prettyprinted
    @prettyprinted  7 ปีที่แล้ว +4

    Thanks for watching everyone. Check out prettyprinted.com for Flask courses.

    • @omarmahamed622
      @omarmahamed622 7 ปีที่แล้ว

      is your website build with flask?

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว

      It isn't, but the next version of it will be.

  • @SadSadDeadM
    @SadSadDeadM 7 ปีที่แล้ว

    When I try to display user username I get info that I'm anonymous user that has no attribute as username.
    Also I get warning "Unauthorized" when I try to enter a page after logging in

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว

      Check your cookies. Is the app creating one when you log in?

  • @ZeroRegretz
    @ZeroRegretz 5 ปีที่แล้ว

    Are you on ubuntu or windows? I'm confused.

    • @prettyprinted
      @prettyprinted  5 ปีที่แล้ว

      Both! You can use Ubuntu on Windows.

  • @jasper5016
    @jasper5016 6 ปีที่แล้ว

    Awesome. You got Thumbs up and new subscriber.

  • @mitaanshuagarwal007
    @mitaanshuagarwal007 7 ปีที่แล้ว

    Thank you! You are amazing!

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว

      You're welcome! Thanks for watching.

  • @chrislam1341
    @chrislam1341 5 ปีที่แล้ว

    the official documentation argues we MUST include the 'next' algo, see the following, after successful login
    next = flask.request.args.get('next')
    if not is_safe_url(next):
    return flask.abort(400)
    could you please explain why is it necessary? Thanks.
    here is the reference: flask-login.readthedocs.io/en/latest/#flask_login.LoginManager.user_loader

  • @GaelGendre
    @GaelGendre 3 ปีที่แล้ว

    Thank you!

  • @faresgeek-dz5692
    @faresgeek-dz5692 8 ปีที่แล้ว

    how to ude materialize.css with flask or django?????

    • @prettyprinted
      @prettyprinted  8 ปีที่แล้ว +1

      There's a Flask plugin called Flask-Materialize. It's similar to Flask-Bootstrap, which I have videos on.

    • @faresgeek-dz5692
      @faresgeek-dz5692 8 ปีที่แล้ว

      Pretty Printed thank you ..you are great...any django videos in futur??

    • @prettyprinted
      @prettyprinted  8 ปีที่แล้ว +1

      Yeah, I'm planning on making them soon. I want to finish up a Flask course first though.

    • @faresgeek-dz5692
      @faresgeek-dz5692 8 ปีที่แล้ว +1

      Pretty Printed thank you😀😀

  • @timothypulliam2177
    @timothypulliam2177 7 ปีที่แล้ว

    I get "Class "User" has no "query" member". I have all of the the necessary packages.

    • @prettyprinted
      @prettyprinted  7 ปีที่แล้ว +1

      Do you have the db.Model in the class declaration?
      class User(UserMixin, db.Model)

    • @timothypulliam2177
      @timothypulliam2177 7 ปีที่แล้ว +1

      Thank you so much for responding.
      Yes. I have my code in an __init__.py file.
      ideone.com/JcZFrQ
      And here is my requirements.txt file, which I have installed PIP packages using virtualenv from.
      pastebin.com/rPpprzHk
      The error occurs at the line "return User.query.get(int(user_id))"

    • @timothypulliam2177
      @timothypulliam2177 7 ปีที่แล้ว +1

      Nevermind. It seems to be working despite this error. I'm not sure why I'm getting the error but it is not a runtime error.

  • @mesosiderite4670
    @mesosiderite4670 3 ปีที่แล้ว

    thank you so much

  • @vinsmokearifka
    @vinsmokearifka 7 ปีที่แล้ว

    thank you anthony

  • @RobertMagier
    @RobertMagier 6 ปีที่แล้ว +1

    Gold :)

  • @coop4476
    @coop4476 4 ปีที่แล้ว

    sqlite:/// not sqlite:////

  • @naheliegend5222
    @naheliegend5222 4 ปีที่แล้ว

    u lost me after 2 minutes...