Django Tutorial #10 - Authentication
Vložit
- čas přidán 20. 06. 2024
- In this Django tutorial series, you'll learn what Django is, how to setup a Django project, and how to use it to make a full web application, complete with a database and authentication.
🚀🥷🏼 Check out Bek Brace's channel for more of his content:
/ @bekbrace
🔥🥷🏼Get access to premium courses on Net Ninja Pro:
netninja.dev/
📂🥷🏼 Access the course files on GitHub:
github.com/BekBrace/django_co...
🧠🥷🏼 HTML Crash Course
• HTML & CSS Crash Cours...
🧠🥷🏼 Python Crash Course
• Python Crash Course #1...
🔗🥷🏼 Django docs:
docs.djangoproject.com/en/5.0/
First of all thanks for your great efforts delivering this course, waiting for other courses and thanks for the NetNinja to support other Devs. At the beginning of this video you said that this is the last chapter of this course, but at the first part of this tutorial you said that at the end you will build an "Inventory Management System", so are there upcoming videos or this is really the last chapter?
This was the best Django course I found on CZcams that was quick and easy to understand. Thanks a lot! :)
Happy to hear that! :)
@NetNinja can you make a tutorial on OOP in Typescript/React 🙏🏽🥺
....and .NET 6😁
Thank you❤️🙌🏽🌹
Tq bro 🙏
@54:14 Did anyone understand this very interesting part? 😵
This one was really confusing, I think fully creating the register page first would be easier to understand
Only apiece 😊😊😊
i was following up the tutorial and overall until this video everyting was fine. But this one is a bit confusing things are done differenlty especialy with routing and classes
there is error in your code and you don't show the video to fix it, I let AI help me to fix it
what kind of error, importing the views?
@@SamuelSibarani-nf9vx
# Fixed login_view Function:
def login_view(request):
error_message = None #---------------------------------------- If the request method is not "POST", error_message is not defined, So Define it as we do here.
if request.method == "POST":
username = request.POST.get("username")
password = request.POST.get("password")
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
next_url = request.POST.get('next') or request.GET.get('next') or 'home'
return redirect(next_url)
else:
error_message = "Invalid Credentials"
context = {'error': error_message}
return render(request, 'accounts/login.html', context )
also, login.html body should look like this:
Login
{% csrf_token %}
{% comment %} hidden input {% endcomment %}
Username
Password
Login
{% if error %}
{{ error }}
{% endif %}
Don't have an account? Register Here
#-------------------------------------#
And the styles.css should look like this:
body{
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
justify-content: center;
align-content: center;
display: grid;
height: 100vh;
}
.container{
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2{
margin-bottom: 20px;
}
.form-group{
margin-bottom: 15px;
}
label{
display: block;
margin-bottom: 5px;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 8px;
box-sizing: border-box;
}
button{
background: #007bff;
color: #fff;
border: none;
padding: 10px 20px;
cursor: pointer;
border-radius: 6px;
}
button:hover{
color: red;
margin-top: 10px;
}
.error{
color: red;
margin-top: 10px;
}