Django Tutorial #14 - URL Parameters

  Рет қаралды 67,482

Net Ninja

Net Ninja

Күн бұрын

Пікірлер: 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)
@anutoshyt
@anutoshyt 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 5 жыл бұрын
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 5 жыл бұрын
from django.urls import path, re_path from . import views urlpatterns = [ path('',views.article_list), re_path('(?P[\w-]+)/$', views.article_detail), ]
@kvnagendra5354
@kvnagendra5354 5 жыл бұрын
@@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_ 4 жыл бұрын
This may help you with Django 3 -> path('/', views.article_detail)
@pyuc
@pyuc Жыл бұрын
2:40 does the name have to be "request" or can you choose a different one
@ЕвгенийПетров-в5п
@ЕвгенийПетров-в5п 5 ай бұрын
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.
@ЕвгенийПетров-в5п
@ЕвгенийПетров-в5п 5 ай бұрын
Django Rules
@ЕвгенийПетров-в5п
@ЕвгенийПетров-в5п 5 ай бұрын
or in Django code (before render) {{ article.title }}
@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
@mustafayilmaz7553
@mustafayilmaz7553 3 жыл бұрын
subscribed, I like your way to show people how it works :)
@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
@luckyluke5257
@luckyluke5257 7 жыл бұрын
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 7 жыл бұрын
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 7 жыл бұрын
thanks
@therhythmatic
@therhythmatic 7 жыл бұрын
I ended up doing something like path('/', views.article_detail) which gave me desirable results.
@amadeuscam1
@amadeuscam1 7 жыл бұрын
path("/", views.article_detail)
@ayushbharadwaj2536
@ayushbharadwaj2536 6 жыл бұрын
thank you , it worked
@agent4140
@agent4140 4 жыл бұрын
Loving the playlist
@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})
@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
@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 2 жыл бұрын
path('/', views.article_detail)
@Lbmaniak
@Lbmaniak 6 жыл бұрын
thx I hope, someday I will watch playlist for Django in production :-)
@ShaffleOne
@ShaffleOne 4 жыл бұрын
same! @The Net Ninja Please!
@CodeProHassam
@CodeProHassam 6 жыл бұрын
Yes thats make sense but what if we just want to retrieve the article with Article ID in DB ??
@DuongTran-zh6td
@DuongTran-zh6td 2 жыл бұрын
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 6 жыл бұрын
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
@damerlasrithandhavakrishna5045
@damerlasrithandhavakrishna5045 4 жыл бұрын
Redirect is not happening It says "reverse for 'list' not found. 'list' is not a valid view function or pattern name"
@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
@ЕвгенийПетров-в5п
@ЕвгенийПетров-в5п 5 ай бұрын
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
@mxt1898
@mxt1898 6 жыл бұрын
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
@sandunnirmala9269
@sandunnirmala9269 7 жыл бұрын
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 7 жыл бұрын
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
@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 6 жыл бұрын
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
@كان-ش9ب
@كان-ش9ب 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 М.
Understanding Django Generic Views
16:29
Chuck Severance
Рет қаралды 14 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
Django QueryDict | GET parameters | django-filter
16:06
BugBytes
Рет қаралды 3 М.
Django Models.py - Django Databases #2
20:50
Codemy.com
Рет қаралды 55 М.
How To Django: How To Work With URL Parameters and Query Strings
8:28
Django Tutorial #12 - Static Files & Images
8:51
Net Ninja
Рет қаралды 152 М.
The Basics of Django Models
37:32
Pretty Printed
Рет қаралды 99 М.
Passing Values Through the URL in Django
14:16
Pretty Printed
Рет қаралды 86 М.
Django ORM Primer - Django QuerySet API and QuerySets
15:07
Very Academy
Рет қаралды 10 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.