L
L
lazyvasya2282020-11-01 15:08:35
Django
lazyvasya228, 2020-11-01 15:08:35

Error: ...uses parameter name '...._id/' which isn't a valid Python identifier. What to do?

I have post apps. When clicking on a post, the user must go to a page whose URL ends with the post's serial number.

In views.py I wrote:

def specific_post(request, post_id):
post = get_object_or_404(Post, pk=post_id)
return render(request, "blog/specific_post.html", {"post": post})

In urls.py I wrote:

path("/", views.specific_post, name = "specific_post"),

As a result, I got this error:

django.core.exceptions.ImproperlyConfigured: URL route '' uses parameter name 'post_id/' which isn' t a valid Python identifier.

help me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
turdakovan, 2021-01-13
@turdakovan

try this in urls.py
path('/', views.specific_post, name='specific_post')
'< int:post_id > /' - must be in quotes (no spaces)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question