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_4 жыл бұрын
thanks bro re_path worked for me but not the first one don't know why
@MrJiaoben4 жыл бұрын
@@EzanAsifEB_ Need '/' at end of the string -> path('/', views.article_detail)
@anutoshyt4 жыл бұрын
Thank you
@anroiduser12224 жыл бұрын
Thanks man, good think I checked the comments, got stuck with that for like an hour
@iliatalebzade87514 жыл бұрын
@@anroiduser1222 same here !
@lucasskywalker5 жыл бұрын
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!
@pushkarsaraf5245 жыл бұрын
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 '.
@positivemindalways5 жыл бұрын
from django.urls import path, re_path from . import views urlpatterns = [ path('',views.article_list), re_path('(?P[\w-]+)/$', views.article_detail), ]
@kvnagendra53545 жыл бұрын
@@positivemindalways tq yaar
@ShaffleOne4 жыл бұрын
@@positivemindalways why cant i just use the new django 3 URL capturing scheme? path('', views.article_detail), ?
@shanithakur_4 жыл бұрын
This may help you with Django 3 -> path('/', views.article_detail)
@pyuc Жыл бұрын
2:40 does the name have to be "request" or can you choose a different one
@ЕвгенийПетров-в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 ай бұрын
Django Rules
@ЕвгенийПетров-в5п5 ай бұрын
or in Django code (before render) {{ article.title }}
@matooj17754 жыл бұрын
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
@mustafayilmaz75533 жыл бұрын
subscribed, I like your way to show people how it works :)
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?
@peymannaji7 жыл бұрын
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),
@wisamkhalid56637 жыл бұрын
thanks
@therhythmatic7 жыл бұрын
I ended up doing something like path('/', views.article_detail) which gave me desirable results.
@amadeuscam17 жыл бұрын
path("/", views.article_detail)
@ayushbharadwaj25366 жыл бұрын
thank you , it worked
@agent41404 жыл бұрын
Loving the playlist
@alphonseraynaud9763 жыл бұрын
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})
@ndifrekeumoren35486 жыл бұрын
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
@010101dddm4 жыл бұрын
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) ]
@lawrencekipchumba29872 жыл бұрын
path('/', views.article_detail)
@Lbmaniak6 жыл бұрын
thx I hope, someday I will watch playlist for Django in production :-)
@ShaffleOne4 жыл бұрын
same! @The Net Ninja Please!
@CodeProHassam6 жыл бұрын
Yes thats make sense but what if we just want to retrieve the article with Article ID in DB ??
@DuongTran-zh6td2 жыл бұрын
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 Жыл бұрын
kippo
@invalidname57206 жыл бұрын
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
@damerlasrithandhavakrishna50454 жыл бұрын
Redirect is not happening It says "reverse for 'list' not found. 'list' is not a valid view function or pattern name"
@truyenkieuvan98836 жыл бұрын
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.
@truyenkieuvan98836 жыл бұрын
I tried it but it doesn't work. Help me please
@truyenkieuvan98836 жыл бұрын
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!
@Nomadvicky6 жыл бұрын
{{article.title}} This is also working for the above condition.
@viduraniroshan51364 жыл бұрын
@@Nomadvicky does not work. 127.0.0.1:8000/articles/django-welcome show all article_list.html
@ЕвгенийПетров-в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
@mxt18986 жыл бұрын
i wanna the user click on the image and guide the user to another page ? i got more confuse any help thank u.
@almuntasirabir45115 жыл бұрын
wrap your image in a tag and set the source of the tag to the page you want to redirect
@sandunnirmala92697 жыл бұрын
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
@sandunnirmala92697 жыл бұрын
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-]+)']
@viduraniroshan51364 жыл бұрын
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
@lilclorox85584 жыл бұрын
check your views.py or paths in URLs folders
@viduraniroshan51364 жыл бұрын
@@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.
@parindapranami62753 жыл бұрын
Check if you are typing --> /django-rules/ INSTEAD OF --> /articles/django-rules/ in the browser
@ahmdzsakib80934 жыл бұрын
how can i do it with Django 3 on path( )
@nepalcodetv62986 жыл бұрын
what will happen if two posts have same slug name ?? How to solve that
@CodeProHassam6 жыл бұрын
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ب4 жыл бұрын
Everything went nice in my project practice until I stuck in this lesson with URLS LESSON 14.