Monday, February 1, 2016

Re: how do I use the url to filter?

Have you completed the official Django tutorial? It covers this exact question in detail.

https://docs.djangoproject.com/en/1.9/intro/tutorial01/

-James

On Feb 1, 2016 3:54 PM, "Dean Johnson" <johnsondean86@gmail.com> wrote:
Hello all,

Hopefully someone can shed some light on this for me..

I have been following a blog tutorial, just to get used to Django, and how everything works with url/views/models etc...

but I have become stuck.

So I am able to go to the admin panel and create,save "blogs", when I visit http://127.0.0.1:8000/blogs - the page shows a title, name and date of several test blogs that have been created, with the header(title) of the blog being a link, that takes me to the blog ID page e http://127.0.0.1:8000/3

in my c:\mysite\blog\urls.py

from django.conf.urls import url, include
from django.views.generic import ListView, DetailView
from blog.models import Post

urlpatterns =[
    url(r'^$', ListView.as_view(queryset=Post.objects.all().order_by("-date")[:25], template_name="blog/blog.html")),
 url(r'^(\d{1,2})/$', ListView.as_view(queryset=Post.objects.all().order_by("id")[:1], template_name="blog/blogpost.html")),  
 ]


As you can probably tell I copied and pasted the first url, for the second one and edited it, This is where I need help!, I can't find anything over the internet that I can fully understand, or guides/tutorials have done it completely different to the point I would have to backtrack and edit loads of stuff.

so how can I make it, if http://127.0.0.1:8000/blog/1 has been clicked it only shows blog entry 1, or if /blog/2 it shows entry 2 etc etc

many thanks everyone.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/39bcac39-3d06-4796-878c-5051f20375f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUB1AP7X0_bmYyARX2U5AXrx3o2N4_h3WouTq3Gppbc0Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment