0

I want to pass value from django custom command to a view.

Custom command: GDA_frontend/GDA_datatables/management/commands/gda_start.py

class Command(BaseCommand):
    help = 'Starts the GDA app with API key for typesense search engine'

    def add_arguments(self, parser):
        parser.add_argument('api_key', type=str)

    def handle(self, *args, **options):
        try:
           # HERE I WANT TO PASS api_key VALUE TO A VIEW

            call_command("runserver", "0.0.0.0:8000")
        except Exception as e:
            self.stdout.write(self.style.ERROR('ERROR: ' + str(e)))

View where i want to pass that value: GDA_frontend/GDA_datatables/views.py

@csrf_protect
def parsing_triggered(request):
    frontendTracker = FrontendTracker()

    if request.method == "POST" and not frontendTracker.parsingStarted:
        # GET THAT API KEY VALUE HERE
    return redirect("index")

Luka
  • 1
  • 2
  • IMHO the simplest way would be to store the value either in a file or in a database field that you read out in the view. Everything else seems complex. – ger.s.brett Aug 30 '22 at 11:47
  • Currently I am storing value in a file and also I want to avoid a database approach. But if that is the easiest way to do it I will keep current implementation or maybe I will switch to a database approach. Thanks – Luka Aug 30 '22 at 11:55

0 Answers0