L
L
Lord_Dantes2019-03-17 21:51:49
Django
Lord_Dantes, 2019-03-17 21:51:49

How to correctly write the ID of the current post in the urls?

It's been a whole 4 hour in dzhang, previously I studied the wordpress system, which is essentially understandable ..
I have this code:

urlpatterns = [
    path('',
         ListView.as_view(queryset=Articles.objects.all().order_by("-date")[:20], template_name="news/posts.html")),
    path('', DetailView.as_view(model = Articles, template_name = "news/post.html"))

]

In the url patterns, the first line displays all the posts, that's right.
In the second line, you need to essentially determine the post ID link and insert it into the path, I tried the following but it turned into a mess because it was taken for a real link.. '^(?P\d+)$'
I understand that this option is very outdated, but where to dig I've finished the video course, tell me.
Thanks to.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lord_Dantes, 2019-03-18
@Lord_Dantes

https://docs.djangoproject.com/en/2.1/topics/http/...
Also, if you need an urgent solution but you find it difficult to understand, here is a video that explains everything:
- Youtube
And the solution to the problem itself: siteurl//

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question