Can't get details page and sure i am right

I am Begging for any help i am circling around this for long time
The method get_absolute_url or even named pattern for details view never work at all
i got this error always while i have tried everything is possible and i am sure that there are no reason

# NoReverseMatch at /blog/posts/add/
Reverse for 'details' with keyword arguments '{'args': {'pk': UUID('066bf6a7-e171-42ef-bc5b-c056a3e15d6c')}}' not found. 1 pattern(s) tried: ['blog/posts/(?P<pk>[0-9]+)/\\Z']

it telling always that the Error caused by my create view function
here is my Post model

class Post(models.Model):
    id = models.UUIDField(default=uuid.uuid4, editable=False, unique=True, primary_key=True)
    slug = models.SlugField(max_length=200, db_index=True, unique=True, editable=False) # add unique=True in slug (never repeat)
    title = models.CharField(max_length=200, db_index=True, blank=False, default='')
    snippet = models.OneToOneField(Snippet, on_delete=models.CASCADE, related_name='post_snippets', blank=True, null=True)
    creator = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="post_creator")
    def get_absolute_url(self):
        """Returns the url to access a particular post instance."""
        return reverse('details', kwargs={ "pk": str(})

Here is my create View

def add_post(request):
    if request.method == 'POST':
        post_form = PostForm(request.POST, request.FILES)
        snippet_form = SnippetForm(request.POST)
        if post_form.is_valid() and snippet_form.is_valid():
            post =
            snpt =
            post.creator = request.user
            post.snippet = snpt
            return redirect('blog:details', args={'pk':}) # or post.get_absolute_url() 
        post_form = PostForm()
        snippet_form = SnippetForm()
    return render(request, 'blog/add_post.html', {'post': post_form, 'snpt': snippet_form})

it should go for details page after create new post
here is the simplest detail view

def post_details(request, pk): 
    post = get_object_or_404(Post, id=pk)
    return render(request, '/blog/post_details.html', {'post':post})

the url pattern is
path('posts/<int:pk>/', post_details, name='details'),

i have made all the changes to the get function and the pattern in view as args and kwargs but still got this error at different patterns

*searched a lot for any likely same as mine but i can’t find any applicable solution

What’s wrong in my simple logic ?
how can i make the args work and be accepted?

I changed referring to index view after creating new post to refer to details, Also
I changed the get_absolute_url to {% url ‘blog:details’ %}" but still the same

the same problem happens when i try to get my all posts index page i got a problem with get_absolute_url method in my template index

Can the problem caused by the templates itself ???
any help please

Hey there!
Checkout the docs for redirect

You pass the keywords arguments directly.

What data type is defined for the pk entry in your url definition? (in the path function)

What data type is your pk for your model?

Side note: I find it generally helpful to always assume that an error is a result of me doing something wrong. Having the attitude that “I’m sure I’m right” can lead to mistakes being overlooked, where the attitude of “I’ve made a mistake” might help you find it.

1 Like

Hello Brother @KenWhitesell, you always saving me
Also thanks for you @leandrodesouzadev Leandro appreciated but that’s was not the problem cause i have changed that a lot of times and tried every pattern of redirect, i have discussed that before with @KenWhitesell and you can check that here

**i can’t believe my self i really felt that i have something wrong in my path url as i was convinced by that uuid is the cause of the problem but really **
i forgot to just write
and try with that, i feel like i am really stupid, but you always save my life brother thanks from my deep heart

aside of that
i was really sure that i am totally have something wrong in my code and convinced 100%
but i heard about some psychological reactions telling that the people don’t like to exhaust themselves or look and search for others bugs or even reply them

but they really like to critic them and show that they are right if they feel a challenge in some verse persons, so i put the words i am sure i am right to just attract the viewers to prove me wrong or help me and not ignoring the question, that’s all
but i knew from the beginning that i am wrong in something

anyway a lot of greetings and thanks