Python Django Tutorial: Full-Featured Web App Part 7 - Login and Logout System

Поділитися
Вставка
  • Опубліковано 8 лют 2025
  • In this Python Django Tutorial, we will be learning how to create an authentication system for our application so that users can login and logout. We are also going to see how we can restrict certain pages so that users must be logged-in in order to access the page. Let's get started...
    The code for this series can be found at:
    github.com/Cor...
    ✅ Support My Channel Through Patreon:
    / coreyms
    ✅ Become a Channel Member:
    / @coreyms
    ✅ One-Time Contribution Through PayPal:
    goo.gl/649HFY
    ✅ Cryptocurrency Donations:
    Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
    Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
    Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
    ✅ Corey's Public Amazon Wishlist
    a.co/inIyro1
    ✅ Equipment I Use and Books I Recommend:
    www.amazon.com...
    ▶️ You Can Find Me On:
    My Website - coreyms.com/
    My Second Channel - / coreymschafer
    Facebook - / coreymschafer
    Twitter - / coreymschafer
    Instagram - / coreymschafer
    #Python #Django

КОМЕНТАРІ • 647

  • @ccandour
    @ccandour 10 місяців тому +115

    If you're using Django 5 or higher you will encounter the problem with accessing the 'logout' page directly from the browser like Corey does. This is because the logout endpoint can be accessed now only using a 'POST' method, and accessing it via a URL is using the 'GET' method. One of the ways you can resolve this issue is to add this short code snippet instead of the standard link element in the navbar:
    {% csrf_token %}
    Logout
    Doesn't look perfect but it works :) Hope this helps!

  • @rishabhkumar5611
    @rishabhkumar5611 6 років тому +490

    I love it how he says - " We'll fix that in just a second " and actually fixes it quite well in a second :)

    • @python4692
      @python4692 3 роки тому +3

      He knows what he's doing!

    • @solomonjayceon1284
      @solomonjayceon1284 3 роки тому

      i guess im asking the wrong place but does anybody know a way to log back into an instagram account..?
      I stupidly lost the login password. I appreciate any help you can offer me

    • @maximomohamed2909
      @maximomohamed2909 3 роки тому

      @Solomon Jayceon instablaster =)

    • @solomonjayceon1284
      @solomonjayceon1284 3 роки тому

      @Maximo Mohamed I really appreciate your reply. I got to the site through google and im in the hacking process now.
      Looks like it's gonna take quite some time so I will get back to you later with my results.

    • @solomonjayceon1284
      @solomonjayceon1284 3 роки тому

      @Maximo Mohamed It did the trick and I now got access to my account again. I'm so happy:D
      Thanks so much, you really help me out !

  • @Canda-fh4xc
    @Canda-fh4xc 6 років тому +191

    This is my second tutorial series with you. I already finished Python Flask Tutorial.
    I watched multiple Django tutorials. Free (blogs and UA-cam) AND Paid(Udemy, edx,..). Your way of teaching is completely different. You are real instructor. You made Django/python really simple to anyone who wants to learn the language. I will make sure to share your UA-cam Tutorial Channel with everyone I know/meet
    Thank you so much,

    • @coreyms
      @coreyms  6 років тому +20

      Thanks!

    • @raskotimagar.21
      @raskotimagar.21 11 місяців тому +1

      while trying logout im getting, This page isn’t workingIf the problem continues, contact the site owner.
      HTTP ERROR 405 error. what should i do?!

    • @Canda-fh4xc
      @Canda-fh4xc 11 місяців тому

      @@raskotimagar.21
      "Method Not Allowed" error.
      Check the URL Routing

    • @phantomtrouper2652
      @phantomtrouper2652 10 місяців тому

      @@raskotimagar.21
      {% if user.is_authenticated %}

      {% csrf_token %}
      Logout
      {% else %}
      Login
      Register
      {% endif %}

    • @thiagokkawakita
      @thiagokkawakita 10 місяців тому

      This method is obsolete, google "405 logout" @@raskotimagar.21

  • @sarthakbhutani7413
    @sarthakbhutani7413 4 роки тому +17

    I really love that : "we haven't created this yet but we will in just a second"!
    God bless you sir.

  • @waleedabdulmanea5301
    @waleedabdulmanea5301 4 роки тому +20

    I like when he says, 'we are gonna fix this in a second', the instructor is reading our minds, good job, and keep the great work, i am one of your students :)

  • @sharathkrishnan1558
    @sharathkrishnan1558 4 роки тому +9

    Not only are these tutorials the best.. But the way you explain, it motivates me to carry on further and it really creates interest in the subject

  • @congcuongnguyen413
    @congcuongnguyen413 2 роки тому +28

    0:31 built-in login/logout page for user
    1:02 import auth_views & create path
    2:53 create templates for those views
    8:37 setting login_redirect_url
    11:28 redirect to login page after register
    12:32 create template for logout page
    16:37 change navigation bar base on login/logout
    18:20 built-in user variable contain current user
    20:55 restriction on certain route if not login
    21:47 create profile view & template & URL
    25:57 login_required decorator
    27:50 setting login_url
    28:43 ?next=...

    • @raskotimagar.21
      @raskotimagar.21 11 місяців тому +6

      while trying logout im getting, This page isn’t workingIf the problem continues, contact the site owner.
      HTTP ERROR 405 error. can you help me please

    • @minsuga2988
      @minsuga2988 11 місяців тому

      Did the error get solved can u tell me how

    • @mychal.b
      @mychal.b 11 місяців тому +2

      @@raskotimagar.21 im having the same error. in the command line it says Method Not Allowed (GET): /logout/ but i dont know how to fix it

    • @mychal.b
      @mychal.b 11 місяців тому

      @@raskotimagar.21
      {% csrf_token %}
      logout
      try this

    • @thiagokkawakita
      @thiagokkawakita 10 місяців тому

      This method is obsolete, google "405 logout"@@mychal.b

  • @jayedm3342
    @jayedm3342 5 років тому +36

    i dont know why the channels sharing knowledge have only 100k+ subs while nonsense channels have milliions ...
    GUYS lets hit that subs red btn and make it to million+

  • @toastrecon
    @toastrecon 5 років тому +7

    Amazing how much functionality is available right out of the box. Thanks, Corey!

  • @aminuolawale1843
    @aminuolawale1843 4 роки тому +2

    Your Flask Series helped me land my current Python job! You are a great teacher !

  • @justinlee3453
    @justinlee3453 3 роки тому +2

    Thanks corey, I've gone over this for the third time, and now this totally makes sense

  • @romnegrillo
    @romnegrillo 4 роки тому +4

    You can still view the login page even though you're logged in. You can change your login route as:
    path("login/", auth_views.LoginView.as_view(template_name = "users/login.html", redirect_authenticated_user=True), name="login"),
    so it will be reditected to blog-home route when you try to access the login page even though you;re authenticated.
    I'm loving this series. Your tutorial is really good. You explain complex problems into simple terms.

  • @erwinnovo3014
    @erwinnovo3014 2 місяці тому +1

    These video tutorials are just truly amazing! Thanks and kudos Corey!

  • @sebastianb2092
    @sebastianb2092 5 років тому +1

    Like I'm watching these videos for 3 days now every day after work and continuingly learning about Python and the Django framework. Love it @Corey Schafer

  • @commonsense1019
    @commonsense1019 Рік тому

    his clearity about the concepts is visible through his advance yet easy to understand explaination

  • @MagnusAnand
    @MagnusAnand 5 років тому +2

    This tutorial is becoming better in every video

  • @pranjalrai-f7g
    @pranjalrai-f7g 10 місяців тому +2

    I love it how you taught any topic in such a easy way
    In my project on opening logout page it was showing 405 error and page breakdown. I have tried various thing but it was not helping so help me in this.

    • @SaulFonsecaGonzalez
      @SaulFonsecaGonzalez Місяць тому

      django 5 requires post method for logout , you need a button for this to work.

  • @jamesskipworth5142
    @jamesskipworth5142 4 роки тому +2

    Suggestion for anyone recreating to add 'redirect_authenticated_user=True' at 4:50 so already logged in users are redirected through the login page. Loved the series though Corey really helped with my school project.

  • @tahhaa906
    @tahhaa906 4 роки тому +4

    I Really like when he says : " that django provides for us ".

  • @vp9041
    @vp9041 6 років тому +3

    Annoyed in the past about not having that next function, truly a nice feature, well explained nice video

  • @roshanpandey5357
    @roshanpandey5357 5 років тому +6

    Well, this video is awesome as others of the same series. Just loved it :-)

  • @tigger2581
    @tigger2581 4 роки тому +1

    hands down best tutorials on youtube. and ive watched many

  • @harwinderthakur9708
    @harwinderthakur9708 5 років тому +4

    I was surprised to see how well crispy forms work with django . It's like a magic don't have to do anything.

  • @shreyas0002
    @shreyas0002 5 років тому +1

    Basically Corey Is A Magician, Guy Knows What problem will arise due to every Small Changes in code and even fixes it!

  • @doniyorabduvokhidov1862
    @doniyorabduvokhidov1862 5 років тому +2

    The best Django tutorial I've ever seen .. thank you for all of your effort .. really appreciate

  • @vegadevelopers
    @vegadevelopers 10 місяців тому +2

    Thank you so much with details explanations and teaching. 👌👌👌 Quality Tutorial!

  • @ABASSANIMERIKUKU
    @ABASSANIMERIKUKU 4 місяці тому +1

    You are just the best.....Django is just sinking into my head

  • @geolegacy2
    @geolegacy2 5 років тому +1

    7 videos in and so far still so good! God bless

  • @olhamarushchak3514
    @olhamarushchak3514 6 років тому +4

    Love you so much!!
    Thank you for this Django course, I've been waiting for so long!

  • @Klutche
    @Klutche 4 роки тому +1

    I can't wait to bring my idea to life with your guidance! Thanks Corey for all you've done! I will follow up once i've deployed my first app!

  • @lightninginmyhands4878
    @lightninginmyhands4878 5 років тому +9

    27:50 `LOGIN_URL` is used to override Django's default URL when a user is trying to access a `login_required` site. We have created our own login route thus `LOGIN_URL` will be assigned to that.

    • @shikunchen8523
      @shikunchen8523 4 роки тому +2

      how can we fix it when login the page always redirects to the home page instead of profile page?

    • @imawo
      @imawo 11 місяців тому

      i'm encountring the same problem . did yo get where's the problem?@@shikunchen8523

  • @andrewchen7710
    @andrewchen7710 6 років тому +4

    Thank you so much Corey! Really helps my startup on building on page! Whether we succeed or not we owe a huge one to you!

    • @coreyms
      @coreyms  6 років тому

      Good luck! What kind of startup?

    • @NphiniT
      @NphiniT 6 років тому +1

      @@coreyms I am gonna use this for my startapp too. It is basically an online bus ticket booking system for travelling within Ghana. I plan on creating Android and iOS Apps for it as well. Any advice and Pointers??

    • @ALEXEIS
      @ALEXEIS 6 років тому

      @@NphiniT
      You need a partner?

    • @NphiniT
      @NphiniT 6 років тому

      @@ALEXEIS How good is your front-end development? E-mail me: nurudeen.karim2016@gmail.com

    • @godfreynolottyogwu8562
      @godfreynolottyogwu8562 6 років тому

      @@NphiniT great idea

  • @mhmt_dmr
    @mhmt_dmr 4 роки тому +2

    Thanks Corey for the perfect lessons. 40 dislike comes from udemy sellers :)

  • @xdlandxd5773
    @xdlandxd5773 5 місяців тому +1

    if someones nav bar doesnt refresh on login or logout, mayby its bcs of ..LoginView... in logout path: path('logout/', auth_views.LoginView.as_view(template_name='users/logout.html'), name='logout'), in urls.py file
    most funny thing on this problem is no one else have this problem... took me a while to fix
    like anyone else, great tutorial, thank you, Corey!

  • @ASADULLAHGALIB25
    @ASADULLAHGALIB25 5 років тому +2

    Corey Schafer, you are the best teacher 👌

  • @GDLAPROD
    @GDLAPROD 2 роки тому +1

    Wow! Impressive. Everything is still relevant.

  • @fariborzseyedi9711
    @fariborzseyedi9711 4 роки тому +1

    Very Very nice videos. thank you Corey. I will suggest this tutorial to every one that want learn Django.

  • @godeytech
    @godeytech 2 роки тому +2

    I really love this. Easy to understand and easy to practice on your own

  • @ashrafulfuad2967
    @ashrafulfuad2967 5 років тому +1

    Thank you so much I learned total django from your tutorial series . now my project is going on

  • @banaras.wala.foreignaala
    @banaras.wala.foreignaala 4 роки тому +1

    Hi Corey, So far so good,
    I want to say thanks for your efforts.

  • @olaniyiajayi8012
    @olaniyiajayi8012 Рік тому +60

    If you have error 405 page on logout page it may be due to latest django version this is what I did to get round it. In users views folder i put this code
    from django.contrib.auth import logout
    def logout_view(request):
    logout(request)
    return render(request, 'users/logout.html')
    then in main project urls I put this in urr parttern list
    path("logout/", user_views.logout_view, name="logout"),
    You can comment out the former url path of logout

    • @jaedenhero548
      @jaedenhero548 Рік тому +1

      Works. Thank you very much!

    • @maxchapin52
      @maxchapin52 11 місяців тому +1

      This worked! Thank you!

    • @danihlzita2345
      @danihlzita2345 11 місяців тому

      Worked out perfectly! Thanks a lot!!!

    • @dragonladycrafts
      @dragonladycrafts 11 місяців тому

      Thank you so much. This helped me out a lot.

    • @jonathanbriones3235
      @jonathanbriones3235 10 місяців тому

      hey guys, this is the way. it worked for me!

  • @akshaykaushik9
    @akshaykaushik9 5 років тому +1

    love you bro.Watched every video available on your channel. Everything learned from you. Feels like i know python as intermediate although it is hard to keep remember every topic.

  • @abdulahamer6238
    @abdulahamer6238 4 роки тому

    Super cool adding features and helping to put students in a user mindset to see functionality and feedback that users will enjoy and will help make things feel intuitive and easy to use

  • @shadow_was_here
    @shadow_was_here 4 роки тому +1

    The Best django tutorial.. Love your teachings man. Great work.

  • @suryamanipandey8002
    @suryamanipandey8002 3 роки тому

    this series is so amazing that its hard to put in words. Thank you for teaching so much in so less time.

  • @namesare4fools
    @namesare4fools 5 років тому +2

    LOVE IT !! I would like to see a more advance django tutorials.. :)

  • @slan7
    @slan7 5 років тому +3

    God-tier tutorials. Thank you, sir.

  • @shailkardani8159
    @shailkardani8159 3 роки тому

    Those who started learning Django for the first dont start. First watch the Flask series by Corey. This series will then be much easier for you. Both the series are master class. You wont find such rich content on any other platform.

  • @liviumircea6905
    @liviumircea6905 5 років тому +4

    amazing ...one of the best tutorials on django

  • @lkarthik1985
    @lkarthik1985 6 років тому +6

    Hi Corey,
    Thanks for this excellent video.

  • @paridhigupta2747
    @paridhigupta2747 3 роки тому

    Best teacher ever.

  • @PrieyudhaAkaditaS
    @PrieyudhaAkaditaS 4 роки тому +1

    The best django tutorial ive ever seen. Thankyou

  • @wentaoqiu4072
    @wentaoqiu4072 5 років тому +1

    You’re a teaching god.

  • @ashG1234
    @ashG1234 6 років тому

    Dear Corey THANK YOU for producing such wonderful videos. Much appreciated. I would request you to produce 2 more videos - 1) Token Based authentication (must required for REST apps) and 2) Use of the token for fetching information.

  • @superrelaxation508
    @superrelaxation508 Рік тому

    Going amazing so far best instructor suggest according to chatgpt and it is true thanks sir

  • @SandeepPareek1
    @SandeepPareek1 3 роки тому

    oh you are the best guy !.... really good tutorials.. keep the good work up .. 1000 thumbs up for you .

  • @Raphael-bq1fc
    @Raphael-bq1fc 2 роки тому +1

    Thank you very much! exactly what I was searching for; even more..

  • @harshbhatt4527
    @harshbhatt4527 3 роки тому

    Sir great work I have not seen a django playlist like this!!!

  • @pratikchakravorty6623
    @pratikchakravorty6623 5 років тому

    Great video. Just one small thing to not let the user go back and access the register and login page after they have logged in add the redirected_authenticated_user=TRUE to the login path in the project's urlconf and also add a check to the register view. You can access the user using request.user

  • @gabrieludoudo2718
    @gabrieludoudo2718 5 років тому +2

    Thanks Sir for giving us the best Django videos on UA-cam , Please can you do a video on how to upload audio file in django

  • @wozdog7425
    @wozdog7425 4 роки тому

    something about you Corey ... I always come away feeling smarter !!

  • @Marek-zt9fy
    @Marek-zt9fy 5 років тому +1

    I love your tutorials, you're amazing man, keep it up!

  • @albertoleaplaza3048
    @albertoleaplaza3048 4 роки тому

    The Best Videos I have seen so far!!!!

  • @sahilbisht3661
    @sahilbisht3661 4 роки тому

    simply awesome thank you so much sir these videos helped me a lot love from India !!

  • @jear3559
    @jear3559 6 років тому +3

    Hi Corey, Thanks for this tutorial... it helps me a lot...

  • @muhammadyaseenmughal3537
    @muhammadyaseenmughal3537 3 роки тому

    BEST SERIES ON INTERNET , I'm LOVING IT :)
    Have a question!
    While accessing profile without login, How can we show Some message on top of Login Page like 'Login First' ?

    • @josephkubinski9118
      @josephkubinski9118 3 роки тому +1

      If else!
      If authen the render
      Else, render normal login page and make an alert message

  • @vladadidko3932
    @vladadidko3932 6 років тому +4

    Thank you, Corey! You're the best)

  • @derekkroeker4582
    @derekkroeker4582 3 роки тому

    3:37
    Got that one many times...
    Didn't get exactly "TemplateDoesNotExist" on the other videos, but this time yes.

  • @ralphcaritativo2033
    @ralphcaritativo2033 5 років тому +2

    DONE TUTORIAL #7! Thank you SENPAI! :)

  • @moebazzi8412
    @moebazzi8412 6 років тому

    AMAZING AND CLEAR TUTORIALS WELL DONE COREY!!!

  • @boomnj127
    @boomnj127 6 років тому +2

    thank you for every thing. you are the best teacher

  • @sarunasj
    @sarunasj 5 років тому +2

    This is amazing. Simple and to the point. I'm now going to go back to Part 1. Thank you!

  • @jamatiasabirdfarming7760
    @jamatiasabirdfarming7760 3 роки тому

    very easy and helpful series, thank you Corey.

  • @osamakhan5381
    @osamakhan5381 5 років тому +2

    Epic Tutorials, Keep up the good work

  • @gavinmurambadoro
    @gavinmurambadoro 2 роки тому

    Django really compares well with Symfony Framework but I feel like it has a better developer experience. Thanks for this.

  • @sanjaydangwal2501
    @sanjaydangwal2501 5 років тому +1

    these tutorials are very helpful.

  • @suneelarumalla
    @suneelarumalla 6 років тому +2

    Nice videos,thanks for all your hard work

  • @piacademy1991
    @piacademy1991 3 роки тому +4

    Can you do a tutorial on how you learn all this stuff, That'd be real cool!!

  • @md.soleymankhan6550
    @md.soleymankhan6550 4 роки тому

    Best Django tutorial.

  • @paulohsgoes1959
    @paulohsgoes1959 4 роки тому

    Another great tutorial of yours. Congrats!

  • @shashanksharmadon4295
    @shashanksharmadon4295 5 років тому +1

    Awesome bro thanks best video ever.....

  • @teddytalks499
    @teddytalks499 5 років тому +2

    Thanks Corey

  • @akramnarejo6221
    @akramnarejo6221 5 років тому +1

    Corey you're amazing really a great blessing. thanks man.

  • @petergames4819
    @petergames4819 2 роки тому

    Love these tutorial videos! Thanks!

  • @saliksheraz6236
    @saliksheraz6236 5 років тому +1

    Great and helpful tutorials

  • @xmuta
    @xmuta 5 років тому +1

    Great video tutorial

  • @TRGIZATION
    @TRGIZATION 3 роки тому

    Your videos are really helpful. Thank you

  • @patrickknows2296
    @patrickknows2296 3 роки тому

    Corey deserve some 🍻

  • @PrashantKumar-nb5ig
    @PrashantKumar-nb5ig 4 роки тому +1

    Great Video sir

  • @Bourne2025
    @Bourne2025 3 роки тому

    Brilliant videos, congratulations!!!!

  • @TUSHAR-mj1en
    @TUSHAR-mj1en 3 роки тому

    Love from India Thank u BHAI

  • @timothybloxsome5802
    @timothybloxsome5802 6 років тому +13

    Fantastic series! plus thanks for all the other Python lessons.
    Just sent a donation by Paypal!
    (Might show up in your account as CryBloxsome )

  • @islamh6042
    @islamh6042 4 роки тому

    Thanks a lot for a great series!

  • @xintongliu8068
    @xintongliu8068 4 роки тому +6

    Brief conclusion for the video:
    1. how to create login, logout and simple profile page.
    Unlike register, login are provided by django, so remember to check settings.py when you play with login.
    2. how to use decorator for profile in view.py.

    • @ahmedbadal3795
      @ahmedbadal3795 4 роки тому

      Hey bro the login form is not generating only login button is there and there is not error

  • @yashshah4842
    @yashshah4842 4 роки тому +5

    By far the best Django Tutorial on the youtube right now. You are truly amazing sir (❁´◡`❁)

  • @hasan8267
    @hasan8267 5 років тому +1

    Great tutorials! Thanks

  • @ahmad-ali14
    @ahmad-ali14 6 років тому +2

    this is the best toturial

  • @juniormichaelseri5212
    @juniormichaelseri5212 6 років тому +1

    Fantastic tutorial!

  • @najeebmoneeb
    @najeebmoneeb 4 роки тому

    A very help full tutorial sir

  • @angeldiaries2331
    @angeldiaries2331 Рік тому

    Truely very informative video