Using the URLconf defined in blog.urls,
Django tried these URL patterns, in this order:
- admin/
- Posts/(?P<post_id>[0-9]+)/$
- ^media/(?P<path>.*)$
The current path, posts/2, didn't match any of these.
from django.contrib import admin
from django.urls import path
from posts import views
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),
path('posts/(?P<post_id>[0-9]+)/$', views.post_details),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
from django.shortcuts import render
from posts.models import Post
# Create your views here.
def home(request):
posts = Post.objects.order_by('pub_date')
return render(request, 'posts/home.html', {'posts': posts})
def post_details(request, post_id):
return render(request, "posts/posts_detail.html", {'post_id': post_id})
--
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...@googlegroups.com.
To post to this group, send email to django...@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/d28eac04-2edc-405e-9942-e883b1e7bff8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Sunday, December 2, 2018 at 10:00:17 AM UTC-8, Jani Tiainen wrote:
Hi.Path is a new url format which uses format of <parser:variable> for exanple like <int:path> . If you want to use regular expressions use re_path instead.
<ehrenf...@gmail.com> kirjoitti su 2. jouluk. 2018 klo 19.42:
When I run http://localhost:8000/posts/2
Here is my .py'sfrom django.contrib import admin
from django.urls import path
from posts import views
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),
path('posts/(?P<post_id>[0-9]+)/$', views.post_details),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
from django.urls import path, re_path
re_path('posts/(?P<post_id>[0-9]+)/$', views.post_details),
I've not looked for a while, but it might even need to be
re_path(r'posts/(?P<post_id>[0-9]+)/$', views.post_details),
Cheers
L.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2f56611d-1510-4f94-b2a2-82aa0a700780%40googlegroups.com.