Django Tutorial #25 - Redirecting After Login

  Рет қаралды 69,653

Net Ninja

Net Ninja

Күн бұрын

Пікірлер: 79
@adebayoadeyemi7817
@adebayoadeyemi7817 5 жыл бұрын
Thank you very much! I have spent the last 3days battling this problem. It's my first django project
@fabianabarca
@fabianabarca Жыл бұрын
What a nice trick! After looking around in the Django Docs and other places I couldn't find anything similar. Worked for me.
@DuongTran-zh6td
@DuongTran-zh6td 2 жыл бұрын
3:30 tạo hàm trong login.html để xử lí request đăng nhập để xác thực (khác với đăng nhập để điều hướng) 5:40 thêm code trong hàm của views để nhận request -->> trang html request mong muốn
@AlexCamargo10
@AlexCamargo10 Ай бұрын
Thank you very much! I've been struggling for days to get this done.
@NetNinja
@NetNinja Ай бұрын
No probs Alex, glad it helped!
@AmanSharma-ij5sl
@AmanSharma-ij5sl 4 жыл бұрын
this is the best playlist on Django
@tarikulislambhuiyan8938
@tarikulislambhuiyan8938 4 жыл бұрын
This was so clear and easy to understand. Thank you very much
@jimiclapton
@jimiclapton 2 жыл бұрын
This saved me a ton of hassle. Works perfectly and makse sense. Thank you!
@shubhampawar456
@shubhampawar456 3 жыл бұрын
hey man thank u i was searching this concept for almost 10 days thank u very much for your guidance
@hassamchundrigar
@hassamchundrigar 5 жыл бұрын
Great tutorial, having all the things I want. Thankyou Sir!
@kostas6915
@kostas6915 2 жыл бұрын
Increadibly Clear! Well done!!!
@craigjohnson8279
@craigjohnson8279 7 жыл бұрын
This is a brilliant series.
@ameerhbaig
@ameerhbaig 4 жыл бұрын
Thanks a lot. I just solved a problem that had taken me an hour
@yusufrumi1626
@yusufrumi1626 4 жыл бұрын
Thank you Shaun. Loving this series.
@jonaslee5002
@jonaslee5002 7 жыл бұрын
Hi love your channel!! I've watched almost all of your playlists! I was wondering though if you could possibly make a PHP tutorial in the future or a Grav CMS tutorial series! Thanks!
@abhikb
@abhikb 3 жыл бұрын
This is still working , Very helpful video
@TorrinLeonard
@TorrinLeonard 2 жыл бұрын
Amazing video! Really clear and very helpful, thank you so much!
@hommastonlimited3187
@hommastonlimited3187 Жыл бұрын
does this still hold true for django 4.
@TorrinLeonard
@TorrinLeonard Жыл бұрын
@@hommastonlimited3187 Been a while since I commented that, but I believe so yes
@haithamali2593
@haithamali2593 3 жыл бұрын
Clear and to the point, thank you very much!!
@_0biwan891
@_0biwan891 6 жыл бұрын
Does it have protection from exploiting? I mean you didn't validate the "next" variable. Will django make it for you?
@DanielLeachTen
@DanielLeachTen 3 жыл бұрын
I can't seem to get the redirect working - instead of directing me to 'create' it redirects me to 'acticles'
@nirajbiswakarma1483
@nirajbiswakarma1483 Жыл бұрын
Just what needed . Thanks
@NetNinja
@NetNinja Жыл бұрын
Thanks for watching Niraj!
@beosoftlabs
@beosoftlabs 6 жыл бұрын
One question Shaun, does the "next" parameter come with Django, I didn't see you add such a functionality...
@AbdulRehman-ju5fd
@AbdulRehman-ju5fd 3 жыл бұрын
Love Ur Channel Bro
@elenaperez6327
@elenaperez6327 3 жыл бұрын
This is a great tutorial! I am new to Django but I can't get my head around the structure of Django, what goes where etc. Does anyone know the best way in which I can learn this so I would be able to make an app myself from scratch? 😃
@sacine3012
@sacine3012 3 жыл бұрын
follow tutorials of this guy about Django from #1! he explains things very clearly and it's easy to understand
@hatembenlajnef9210
@hatembenlajnef9210 3 жыл бұрын
thank you very much for this tutorial
@MrSiamtea
@MrSiamtea 4 жыл бұрын
Great turtorial...👍🏻
@youtubestar5531
@youtubestar5531 Жыл бұрын
Perfect solution 🥰
@hiteshchoudhary3412
@hiteshchoudhary3412 7 жыл бұрын
Please try to finish this Django series in this year only. Start new series from New year???
@ramonoscar
@ramonoscar 7 жыл бұрын
Awesome, you should make a pm2 and or webpack tutorial please
@beosoftlabs
@beosoftlabs 6 жыл бұрын
Awesome as usual!
@MrLotrus
@MrLotrus 6 жыл бұрын
what if user made mistake first try and authorized at second attempt? Redirect to required page wouldn't work, I guess.
@johnyonardpauly5601
@johnyonardpauly5601 7 жыл бұрын
Really love this channel!! Can you make a series of Laravel 5.5 tutorial from scratch?? Thank you merry xmas :)
@prasannadeshpande4435
@prasannadeshpande4435 2 жыл бұрын
Thanks for the video.
@NetNinja
@NetNinja 2 жыл бұрын
You're very welcome :)
@naveen3046
@naveen3046 4 жыл бұрын
After login it redirected to article list page it doesn't goes to creat page what to do
@PutolevePetitliph
@PutolevePetitliph 4 жыл бұрын
Same Issue here :-(
@DanielLeachTen
@DanielLeachTen 3 жыл бұрын
@@PutolevePetitliph Same!
@aadityanaik1655
@aadityanaik1655 3 жыл бұрын
top notch dude
@Akonitx
@Akonitx Жыл бұрын
Amazing. Thanks
@kodieivie
@kodieivie 7 жыл бұрын
hey bro, what are your thoughts on flask?
@АндрейКулагин-е1ш
@АндрейКулагин-е1ш Жыл бұрын
Спасибо, помогло
@Carnage-X
@Carnage-X 6 жыл бұрын
This process is not working for me, i am always redirected to the article list page. I am using Django 2.0.1. Everything is same from the beginning, i've followled your tutorials from the beginning,except for i've used 'path' instead of 'url'. Rest is Same.
@malikmstr5133
@malikmstr5133 6 жыл бұрын
I'm also using Django 2.0.1 and it's working for me without getting any error message... check your code maybe you did a mistake
@Carnage-X
@Carnage-X 6 жыл бұрын
yeah! i did a mistake and realized it much latter, I am using HttpResponseRedirect,
@ezragongati162
@ezragongati162 6 жыл бұрын
i am also dude where can use that HttpResponseRedirect
@some_carbon5586
@some_carbon5586 4 жыл бұрын
I'm getting a NoReverseMatch at /accounts/login/ error after entering the right user info
@harambe8577
@harambe8577 4 жыл бұрын
did you solve it?
@alessandromarcellini8147
@alessandromarcellini8147 3 жыл бұрын
you're getting this error becouse by default your login url of the project is: /accounts/login/. You just have to set the variable: LOGIN_URL = '/path/to/login/' into your settings.py and you're good to go.
@rishabhjain2084
@rishabhjain2084 5 жыл бұрын
A perfect tutorial......
@_jofredtrigo
@_jofredtrigo 6 жыл бұрын
hello sir what if i manually put next = /url on my browser can they access it directly'?
@vic3814
@vic3814 7 жыл бұрын
hi man, could you maybe explain how you can add things to a shopping cart and that stuff in css? I can't find it anywhere.
@tobiasmaier8640
@tobiasmaier8640 7 жыл бұрын
Vic Vercruysse Why would you do that with Css? you would definitly do that wit javascript, not Css
@lesterjohnson3190
@lesterjohnson3190 6 жыл бұрын
Hey Vic. Try the css animation playlist
@djsamke384
@djsamke384 6 жыл бұрын
Love this code!!!
@muhammadhasan8076
@muhammadhasan8076 4 жыл бұрын
Thanks boss
@yt-1161
@yt-1161 3 жыл бұрын
throws Error NoReverseMatch at /accounts/login/ Reverse for '' not found. '' is not a valid view function or pattern name.
@DuongTran-zh6td
@DuongTran-zh6td 2 жыл бұрын
5:38 / 7:45
@firstnamelastname7248
@firstnamelastname7248 6 жыл бұрын
I find a bug here. If you deliberately enter wrong username/password, the next url is gone. Then you log in correctly, it won't redirect to where you are from. Another problem is when you are in page A or B or C (no login_required) and click login, it renders login page. After entering username/pwd, it does not redirect back to Page A or B or C. request.META.HTTP_REFERER remember the address where you are from.
@firstnamelastname7248
@firstnamelastname7248 6 жыл бұрын
There are three ways to login. 1. directly type accounts/login 2. click login form button and redirect to login page 3. meets @login_required and redirect to login page These three ways all contains valid and invalid forms, so there will be totally six cases here. I want to paste my code here which pass these conditions. For #1, it will redirect to /. For #2 and #3, it will direct to last page you are viewing. Even you deliberately enter incorrect authentications, the last_referer still store your last page address. My code is as follows: views.py def login_view(request): if request.method == "POST": form = AuthenticationForm(data=request.POST) if form.is_valid(): user = form.get_user() login(request, user) # I use redirect() instead of render(), because I want to leave login page forever. return redirect(request.POST.get('next').strip()) if not form.is_valid(): # last_referer is the last address you are visiting before you come to login page. # No matter how many times you authenticate incorrectly, \ # the last_referer still remains the same in browser. context = {'form':form, 'last_referer': request.POST.get('next','')} # I use render() instead of redirect(), because I want to catch error hints provided by form. return render(request, 'accounts/login.html', context) if request.method == "GET": form = AuthenticationForm() context = {'form': form} return render(request, 'accounts/login.html', context) login.html {% csrf_token %} {{ form }} login {{ last_referer }} solve the incorrect authentication {{ request.GET.next }} solves #3 {{request.META.HTTP_REFERER }} solves #2 / solves #1
@firstnamelastname7248
@firstnamelastname7248 6 жыл бұрын
Here is codes about logout and redirect to page. I grab these from stackoverflow. views.py def logout_view(request): logout(request) return render(request, 'accounts/logout.html') logout.html You've been logged out. {% if '/accounts/logout/' not in request.META.HTTP_REFERER %} You will be redirected in a second {% endif %} {% if '/accounts/logout/' not in request.META.HTTP_REFERER %} document.location.href = '{{ request.META.HTTP_REFERER }}'; {% endif %}
@hyderabadicartoonnetwork
@hyderabadicartoonnetwork 7 жыл бұрын
Hi Shaun. Let me tell You one thing. When I find your channel for the first time, First thing that strike on my mind is "This channel is a Treasure" :-) God Bless You. If Possible in near future, Will you make a series for "Ruby" BTW Thanks alot for the whole Playlist.
@ahmedghallab5342
@ahmedghallab5342 Жыл бұрын
شكرا thanks
@Lbmaniak
@Lbmaniak 6 жыл бұрын
thx
@MrSaeedalhakimi
@MrSaeedalhakimi 7 жыл бұрын
cooool next please
@learnanywhere5736
@learnanywhere5736 7 жыл бұрын
i m waiting for next tutor..
@gopeshyadav3841
@gopeshyadav3841 4 жыл бұрын
But in my url there is no next field.. I redirect the users if they want to comment or like blog using return redirect('website:login') where website is app name, after that url in my brower is 127.0.0.1:8000/login. How do I reverse back to my blog comment section.
@alessandromarcellini8147
@alessandromarcellini8147 3 жыл бұрын
I know I'm replying after 8 months but this could be useful for others if you've already solved the problem ahah. I recommend checking out the usage of the @login_required django decorator. It will add the next field automatically.
@RaynerDaCruz
@RaynerDaCruz 3 жыл бұрын
@@alessandromarcellini8147 Just to add to your comment, the @login_required decorator is covered in a previous video ( I think its the one before this ) of this video series.
@runthomas
@runthomas 6 жыл бұрын
missed out the main information...where is the next variable set to be articles/create...where is this done ???? without that ..all this video is useless..
@NetNinja
@NetNinja 6 жыл бұрын
Did you watch the previous video in the playlist? If you did then you'll notice It's the @login_required decorator which redirects us and generates this URL & query string for 'next'.
@runthomas
@runthomas 6 жыл бұрын
sorry no ...i diddnt i was just looking for redirection and ?next stuff on youtube and your vid flashed up.
@dfhfdgfgdfshdfhe8257
@dfhfdgfgdfshdfhe8257 6 жыл бұрын
dislike for "hideen"
@mdrafiakhtar577
@mdrafiakhtar577 6 жыл бұрын
He corrected it thereafter.
@midhunmohan5112
@midhunmohan5112 5 жыл бұрын
Lol is that a reason to dislike?
@lctechnologies9393
@lctechnologies9393 2 жыл бұрын
How do you manually ensure request.GET.next for certain urls? For example in an eCommerce web app, a user may browse items while being logged in. If a user is logged in and registered, but hasn't entered shipping information (not required to register) and tries to purchase an item, I want to redirect that user to the shipping address form that I have set up, and after they successfully enter their shipping address, redirect them to the purchasing page.
Django Tutorial #26 - Model Forms
13:08
Net Ninja
Рет қаралды 45 М.
Learn Django Class Based Views - RedirectView - Theory and Examples
21:57
Login and Logout - Django Wednesdays ECommerce 7
20:33
Codemy.com
Рет қаралды 16 М.
Adding a session timeout in Django
15:44
Cloud With Django
Рет қаралды 10 М.
Django Tutorial - Login, Logout and User Authentication
13:44
Tech With Tim
Рет қаралды 132 М.
Passing Values Through the URL in Django
14:16
Pretty Printed
Рет қаралды 86 М.
How to use Django Forms
8:55
Tony Teaches Tech
Рет қаралды 24 М.
Django Authentication Basics
19:38
Pretty Printed
Рет қаралды 109 М.
Implementing POST Redirect in Django
8:05
Chuck Severance
Рет қаралды 12 М.