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")

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. Commented Aug 30, 2022 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 Commented Aug 30, 2022 at 11:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.