Search code examples
djangodjango-viewsdjango-sitetree

Returning PK from URL in Django UpdateView


For example, I am using Django's generic views and in my url, there is a PK. Now, django is rendering that context_object, but not PK from url to my view. I need that function when I want to use sitetree in Django.

So I just need to make generic view in django rendering pk from url.

How to do that?


Solution

  • If it is an UpdateView, you will have a form variable available in your template.Just use form.instance.id or whatever your id is called

    In DeleteView, you will have a variable called "object". Simply use object.id

    The same applies to others:Since your model always has an id (since it is in the url I assume you are not creating), you can reach it