DJANGO model instance get by variable

from django.shortcuts import get_object_or_404
from yourapp.models import YourModel

# Step 1: Define the variable containing the primary key value
your_model_id = 1

# Step 2: Use the get_object_or_404 function to retrieve the model instance
your_model_instance = get_object_or_404(YourModel, id=your_model_id)

# Now, 'your_model_instance' contains the instance of YourModel with the specified ID