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
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!
I was just running into this issue yesterday! Thanks!! Would like to see a way we can keep the anchor instead of having to use a btn though.
Thanks man
tysm!
Thanks man.
Thanks a lot
I love it how he says - " We'll fix that in just a second " and actually fixes it quite well in a second :)
He knows what he's doing!
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
@Solomon Jayceon instablaster =)
@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.
@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 !
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,
Thanks!
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?!
@@raskotimagar.21
"Method Not Allowed" error.
Check the URL Routing
@@raskotimagar.21
{% if user.is_authenticated %}
{% csrf_token %}
Logout
{% else %}
Login
Register
{% endif %}
This method is obsolete, google "405 logout" @@raskotimagar.21
I really love that : "we haven't created this yet but we will in just a second"!
God bless you sir.
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 :)
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
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=...
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
Did the error get solved can u tell me how
@@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
@@raskotimagar.21
{% csrf_token %}
logout
try this
This method is obsolete, google "405 logout"@@mychal.b
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+
Trust me I have
Amazing how much functionality is available right out of the box. Thanks, Corey!
Your Flask Series helped me land my current Python job! You are a great teacher !
Thanks corey, I've gone over this for the third time, and now this totally makes sense
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.
Thanks
These video tutorials are just truly amazing! Thanks and kudos Corey!
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
his clearity about the concepts is visible through his advance yet easy to understand explaination
This tutorial is becoming better in every video
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.
django 5 requires post method for logout , you need a button for this to work.
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.
I Really like when he says : " that django provides for us ".
Annoyed in the past about not having that next function, truly a nice feature, well explained nice video
Well, this video is awesome as others of the same series. Just loved it :-)
hands down best tutorials on youtube. and ive watched many
I was surprised to see how well crispy forms work with django . It's like a magic don't have to do anything.
Basically Corey Is A Magician, Guy Knows What problem will arise due to every Small Changes in code and even fixes it!
The best Django tutorial I've ever seen .. thank you for all of your effort .. really appreciate
Thank you so much with details explanations and teaching. 👌👌👌 Quality Tutorial!
You are just the best.....Django is just sinking into my head
7 videos in and so far still so good! God bless
Love you so much!!
Thank you for this Django course, I've been waiting for so long!
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!
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.
how can we fix it when login the page always redirects to the home page instead of profile page?
i'm encountring the same problem . did yo get where's the problem?@@shikunchen8523
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!
Good luck! What kind of startup?
@@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??
@@NphiniT
You need a partner?
@@ALEXEIS How good is your front-end development? E-mail me: nurudeen.karim2016@gmail.com
@@NphiniT great idea
Thanks Corey for the perfect lessons. 40 dislike comes from udemy sellers :)
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!
hey can u tell me the fix for this?
Corey Schafer, you are the best teacher 👌
Wow! Impressive. Everything is still relevant.
Very Very nice videos. thank you Corey. I will suggest this tutorial to every one that want learn Django.
I really love this. Easy to understand and easy to practice on your own
Thank you so much I learned total django from your tutorial series . now my project is going on
Hi Corey, So far so good,
I want to say thanks for your efforts.
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
Works. Thank you very much!
This worked! Thank you!
Worked out perfectly! Thanks a lot!!!
Thank you so much. This helped me out a lot.
hey guys, this is the way. it worked for me!
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.
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
The Best django tutorial.. Love your teachings man. Great work.
this series is so amazing that its hard to put in words. Thank you for teaching so much in so less time.
LOVE IT !! I would like to see a more advance django tutorials.. :)
God-tier tutorials. Thank you, sir.
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.
amazing ...one of the best tutorials on django
Hi Corey,
Thanks for this excellent video.
Best teacher ever.
The best django tutorial ive ever seen. Thankyou
You’re a teaching god.
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.
Going amazing so far best instructor suggest according to chatgpt and it is true thanks sir
oh you are the best guy !.... really good tutorials.. keep the good work up .. 1000 thumbs up for you .
Thank you very much! exactly what I was searching for; even more..
Sir great work I have not seen a django playlist like this!!!
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
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
something about you Corey ... I always come away feeling smarter !!
I love your tutorials, you're amazing man, keep it up!
The Best Videos I have seen so far!!!!
simply awesome thank you so much sir these videos helped me a lot love from India !!
Hi Corey, Thanks for this tutorial... it helps me a lot...
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' ?
If else!
If authen the render
Else, render normal login page and make an alert message
Thank you, Corey! You're the best)
3:37
Got that one many times...
Didn't get exactly "TemplateDoesNotExist" on the other videos, but this time yes.
DONE TUTORIAL #7! Thank you SENPAI! :)
AMAZING AND CLEAR TUTORIALS WELL DONE COREY!!!
thank you for every thing. you are the best teacher
This is amazing. Simple and to the point. I'm now going to go back to Part 1. Thank you!
very easy and helpful series, thank you Corey.
Epic Tutorials, Keep up the good work
Django really compares well with Symfony Framework but I feel like it has a better developer experience. Thanks for this.
these tutorials are very helpful.
Nice videos,thanks for all your hard work
Can you do a tutorial on how you learn all this stuff, That'd be real cool!!
Best Django tutorial.
Another great tutorial of yours. Congrats!
Awesome bro thanks best video ever.....
Thanks Corey
Corey you're amazing really a great blessing. thanks man.
Love these tutorial videos! Thanks!
Great and helpful tutorials
Great video tutorial
Your videos are really helpful. Thank you
Corey deserve some 🍻
Great Video sir
Brilliant videos, congratulations!!!!
Love from India Thank u BHAI
Fantastic series! plus thanks for all the other Python lessons.
Just sent a donation by Paypal!
(Might show up in your account as CryBloxsome )
Thanks!
Thanks a lot for a great series!
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.
Hey bro the login form is not generating only login button is there and there is not error
By far the best Django Tutorial on the youtube right now. You are truly amazing sir (❁´◡`❁)
Great tutorials! Thanks
this is the best toturial
Fantastic tutorial!
A very help full tutorial sir
Truely very informative video