No video

Django Tutorial #14 - URL Parameters

  Рет қаралды 66,656

Net Ninja

Net Ninja

Күн бұрын

DONATE :) - www.paypal.me/...
----- COURSE LINKS:
+ Python tutorials - goo.gl/xD2AvX
+ Course files - github.com/iam...
+ Django docs - docs.djangopro...
+ Atom editor - atom.io/a
+ CMDER - cmder.net/
======== Other Tutorials =========
----- NODE.JS TUTORIALS
• Node JS Tutorial for B...
----- MONGODB TUTORIALS
• MongoDB Tutorial for B...
----- SUBSCRIBE TO CHANNEL - / @netninja
======== Social Links ==========
Twitter - @TheNetNinja - / thenetninjauk
Patreon - / thenetninja

Пікірлер: 76
@WaleedAsender
@WaleedAsender 4 жыл бұрын
This has been significantly changed in Django 3, this could be done like this: path('/', views.article_detail), where the first slug "" is the name of the parameter which could be any name; "abc", "the_slug", etc. If you still insist on using regex then there is one thing to change; the method name instead of "url" use "re_path": re_path(r'^(?P[\w-]+)/$', views.article_detail),
@EzanAsifEB_
@EzanAsifEB_ 4 жыл бұрын
thanks bro re_path worked for me but not the first one don't know why
@MrJiaoben
@MrJiaoben 4 жыл бұрын
@@EzanAsifEB_ Need '/' at end of the string -> path('/', views.article_detail)
@anutoshpaul7203
@anutoshpaul7203 4 жыл бұрын
Thank you
@anroiduser1222
@anroiduser1222 4 жыл бұрын
Thanks man, good think I checked the comments, got stuck with that for like an hour
@iliatalebzade8751
@iliatalebzade8751 4 жыл бұрын
@@anroiduser1222 same here !
@lucasskywalker
@lucasskywalker 5 жыл бұрын
You are a brilliant instructor. Absolutely perfectly paced. Clean presentation. Very easy to listen to your voice for days. Please continue you're amazing channel. Thank you!
@pushkarsaraf524
@pushkarsaraf524 4 жыл бұрын
Great tutorial, for Django 2 and above, URL dispatching or URL capturing using RegEx --> make sure you import ' re_path from 'django.urls ' and use ' re_path( ... ) ' inside ' urlpatterns '.
@positivemindalways
@positivemindalways 4 жыл бұрын
from django.urls import path, re_path from . import views urlpatterns = [ path('',views.article_list), re_path('(?P[\w-]+)/$', views.article_detail), ]
@kvnagendra5354
@kvnagendra5354 4 жыл бұрын
@@positivemindalways tq yaar
@ShaffleOne
@ShaffleOne 4 жыл бұрын
@@positivemindalways why cant i just use the new django 3 URL capturing scheme? path('', views.article_detail), ?
@shanithakur_
@shanithakur_ 3 жыл бұрын
This may help you with Django 3 -> path('/', views.article_detail)
@kalekber
@kalekber 5 жыл бұрын
django v2: urlpatterns = [ path('', views.article_list), path('/', views.article_detail) ]
@weicao4101
@weicao4101 5 жыл бұрын
good, it is useful
@maxedin7910
@maxedin7910 5 жыл бұрын
thanks man
@matooj1775
@matooj1775 4 жыл бұрын
If anyone has problems with the slug thing just try this: path('/', views.article_detail) it worked for me so try it out if you want
@alphonseraynaud976
@alphonseraynaud976 3 жыл бұрын
I actually came up with my own solution to this earlier in this tutorial: in urls.py I wrote: for article in Article.objects.all(): urlpatterns.append(path(f'{article.slug}/',views.article_details)) and then in views.py: def article_details(request): for a in Article.objects.all(): if "/"+a.slug+"/" == request.path: article = a return render(request, 'article.html', {'article':article})
@agent4140
@agent4140 4 жыл бұрын
Loving the playlist
@Lbmaniak
@Lbmaniak 5 жыл бұрын
thx I hope, someday I will watch playlist for Django in production :-)
@ShaffleOne
@ShaffleOne 4 жыл бұрын
same! @The Net Ninja Please!
@mustafayilmaz7553
@mustafayilmaz7553 2 жыл бұрын
subscribed, I like your way to show people how it works :)
@ndifrekeumoren3548
@ndifrekeumoren3548 6 жыл бұрын
Thanks for this great tutorial, Shaun. Please, can you update it to version 2.0 as name capturing group is quite different? thanks once again looking forward to the update
@luckyluke5257
@luckyluke5257 6 жыл бұрын
It looks like a new version of Django 2.0 has come out, and now you can add it using PATH, not URL. How to do it now?
@peymannaji
@peymannaji 6 жыл бұрын
We need to import re_path in urls.py : from django.urls import path, re_path And then you need to add : re_path('(?P[\w-]+)/$', views.article_detail),
@wisamkhalid5663
@wisamkhalid5663 6 жыл бұрын
thanks
@therhythmatic
@therhythmatic 6 жыл бұрын
I ended up doing something like path('/', views.article_detail) which gave me desirable results.
@amadeuscam1
@amadeuscam1 6 жыл бұрын
path("/", views.article_detail)
@ayushbharadwaj2536
@ayushbharadwaj2536 6 жыл бұрын
thank you , it worked
@pyuc
@pyuc Жыл бұрын
2:40 does the name have to be "request" or can you choose a different one
@010101dddm
@010101dddm 4 жыл бұрын
why am i getting 404 error? from django.urls import path, re_path from . import views urlpatterns = [ path('', views.index), re_path('', views.article_detail) ]
@lawrencekipchumba2987
@lawrencekipchumba2987 Жыл бұрын
path('/', views.article_detail)
@user-pb2mn7go2p
@user-pb2mn7go2p Ай бұрын
Shaun typed the urls BY HAND. 7:04 The links on the homepage still refer to .../article/# and don't even match our regex so nothing happens.
@user-pb2mn7go2p
@user-pb2mn7go2p Ай бұрын
Django Rules
@user-pb2mn7go2p
@user-pb2mn7go2p Ай бұрын
or in Django code (before render) {{ article.title }}
@CodeProHassam
@CodeProHassam 5 жыл бұрын
Yes thats make sense but what if we just want to retrieve the article with Article ID in DB ??
@damerlasrithandhavakrishna5045
@damerlasrithandhavakrishna5045 4 жыл бұрын
Redirect is not happening It says "reverse for 'list' not found. 'list' is not a valid view function or pattern name"
@DuongTran-zh6td
@DuongTran-zh6td Жыл бұрын
5:25 tao url slug nhan gia tri client nhap sau do chuyen qua tham so ben view 7:00 tao view nhan gia tri tu bien slug ben url
@trzztrzz2477
@trzztrzz2477 Жыл бұрын
kippo
@invalidname5720
@invalidname5720 5 жыл бұрын
Using the URLconf defined in blogtastic.urls, Django tried these URL patterns, in this order: admin/ about/ articles/ articles/ (?P[\w-]+)/ ^static/(?P.*)$ The current path, articles/hello, didn't match any of these. I'm getting this error
@truyenkieuvan9883
@truyenkieuvan9883 6 жыл бұрын
I had done that " url(r'^(?P[\w-]+)/$',views.article_detail)," and "def article_detail(request, slug): return HttpResponse(slug)" but when i had clicked on title of article, nothing happened. Can you give me some reason.
@truyenkieuvan9883
@truyenkieuvan9883 6 жыл бұрын
I tried it but it doesn't work. Help me please
@truyenkieuvan9883
@truyenkieuvan9883 6 жыл бұрын
base on video 15, I use "url(r'^/(?P[\w-]+)/$',views.article_detail)" and in article_list.html, I write "{{article.title}}" and it work correctly. Can you explain to me? Thanks so much!
@Nomadvicky
@Nomadvicky 6 жыл бұрын
{{article.title}} This is also working for the above condition.
@viduraniroshan5136
@viduraniroshan5136 4 жыл бұрын
@@Nomadvicky does not work. 127.0.0.1:8000/articles/django-welcome show all article_list.html
@user-pb2mn7go2p
@user-pb2mn7go2p Ай бұрын
it might be way too late but Shaun typed those urls BY HAND. in the templates {{ article.title }} we still didn't change the href="#" part so article titles refer to .../articles/# and not to .../articles/django-rules yet there's and an answer from your timeline :D actually. {{ article.slug }} in href="{{ article.slug }}" like this {{ article.title }} works
@sandunnirmala9269
@sandunnirmala9269 6 жыл бұрын
i have this error Error during template rendering In template C:\Users\Sandun-PC\Documents\djangoweb\myweb\templates\base_layout.html, error at line 0 'articles' is not a registered namespace
@sandunnirmala9269
@sandunnirmala9269 6 жыл бұрын
if i remove articles then i got this error Error during template rendering In template C:\Users\Sandun-PC\Documents\djangoweb\myweb\templates\base_layout.html, error at line 0 Reverse for 'detail' with keyword arguments '{'slug': ''}' not found. 1 pattern(s) tried: ['articles\\/(?P[\\w-]+)']
@viduraniroshan5136
@viduraniroshan5136 4 жыл бұрын
in any way i couldn't fix my problem regard just show only articles_list.html. i can't load single object in my browser
@lilclorox8558
@lilclorox8558 4 жыл бұрын
check your views.py or paths in URLs folders
@viduraniroshan5136
@viduraniroshan5136 4 жыл бұрын
@@lilclorox8558 i did everything. I wrote codes that are exactly type you & not changed even a letter. (I changed my variables name and others as my code). I think my python version or django version is not compatible with your code.
@parindapranami6275
@parindapranami6275 3 жыл бұрын
Check if you are typing --> /django-rules/ INSTEAD OF --> /articles/django-rules/ in the browser
@mxt1898
@mxt1898 5 жыл бұрын
i wanna the user click on the image and guide the user to another page ? i got more confuse any help thank u.
@almuntasirabir4511
@almuntasirabir4511 5 жыл бұрын
wrap your image in a tag and set the source of the tag to the page you want to redirect
@ahmdzsakib8093
@ahmdzsakib8093 4 жыл бұрын
how can i do it with Django 3 on path( )
@nepalcodetv6298
@nepalcodetv6298 6 жыл бұрын
what will happen if two posts have same slug name ?? How to solve that
@CodeProHassam
@CodeProHassam 5 жыл бұрын
True thats what i am thinking , we should retrieve atricle by article ID not slug, but this is just for educational purpose i think good to learn this too
@user-kd1ww1go4u
@user-kd1ww1go4u 4 жыл бұрын
Everything went nice in my project practice until I stuck in this lesson with URLS LESSON 14.
Django Tutorial #15 - Named URL's
8:13
Net Ninja
Рет қаралды 44 М.
GTA 5 vs GTA San Andreas Doctors🥼🚑
00:57
Xzit Thamer
Рет қаралды 25 МЛН
This Dumbbell Is Impossible To Lift!
01:00
Stokes Twins
Рет қаралды 42 МЛН
1ОШБ Да Вінчі навчання
00:14
AIRSOFT BALAN
Рет қаралды 4,6 МЛН
КТО ЛЮБИТ ГРИБЫ?? #shorts
00:24
Паша Осадчий
Рет қаралды 4,3 МЛН
Django Tutorial #20 - Saving Users
12:19
Net Ninja
Рет қаралды 44 М.
Python Django Explained In 8 Minutes
8:11
Dennis Ivy
Рет қаралды 285 М.
Django Tutorial - SQLite3 DataBase Tutorial
22:49
Tech With Tim
Рет қаралды 179 М.
Django Tutorial #25 - Redirecting After Login
7:46
Net Ninja
Рет қаралды 69 М.
How to use Django Forms
8:55
Tony Teaches Tech
Рет қаралды 20 М.
Django Tutorial #22 - Logging Users In
5:33
Net Ninja
Рет қаралды 36 М.
Passing Values Through the URL in Django
14:16
Pretty Printed
Рет қаралды 86 М.
Django Tutorial #16 - Article Detail Template
6:06
Net Ninja
Рет қаралды 37 М.
Django Tutorial #21 - Login Form
9:59
Net Ninja
Рет қаралды 92 М.
GTA 5 vs GTA San Andreas Doctors🥼🚑
00:57
Xzit Thamer
Рет қаралды 25 МЛН