Splunk Dev

Django in splunk

marisstella
Explorer

To create a new endpoint named get_ticket_id in your Django application, follow these steps:

Steps:

  1. Define a function in your views to handle the logic of accepting two strings, calling the desired function, and returning the result.

  2. Create a URL route to point to the new view function.

  3. Implement the logic for the function you want to call.

    Example Code:

    views.py

    from django.http import JsonResponse
    from django.views.decorators.csrf import csrf_exempt
    import json
    
    # Sample function to process the two strings
    def process_strings(string1, string2):
        # Example logic to generate a ticket ID
        return f"Ticket-{string1[:3]}-{string2[:3]}"
    
    @csrf_exempt
    def get_ticket_id(request):
        if request.method == "POST":
            try:
                # Parse the request body
                data = json.loads(request.body)
                string1 = data.get("string1")
                string2 = data.get("string2")
    
                if not string1 or not string2:
                    return JsonResponse({"error": "Both 'string1' and 'string2' are required."}, status=400)
    
                # Call the processing function
                ticket_id = process_strings(string1, string2)
                return JsonResponse({"ticket_id": ticket_id}, status=200)
    
            except json.JSONDecodeError:
                return JsonResponse({"error": "Invalid JSON format."}, status=400)
    
        return JsonResponse({"error": "Only POST requests are allowed."}, status=405)

     

0 Karma

marisstella
Explorer

Oh, thanks for the confirmation.. 

0 Karma

VatsalJagani
SplunkTrust
SplunkTrust

@marisstella- Kindly please accept the answer @isoutamo if that help you resolve/understand your query by clicking on "Accept as Solution" so future Splunk Community users will get benefited from your question as well.

0 Karma

isoutamo
SplunkTrust
SplunkTrust
If I have understood right Django is no longer supported on recent spunk versions https://docs.splunk.com/Documentation/Splunk/9.4.0/Installation/ChangesforSplunkappdevelopers ?
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...