1

I have a page called controlpanel, where I can start/stop scripts. When the button for start and stop scripts is pressed, it return the same page with button color changed and I want to delete query string.

view.py

def controlpanel(request):
   data = {'paypal': paypal_, 'cpu': cpu_usage, 'active': active_task ...}
   return render(request, 'admin/controlpanel.html', context=data) 

def startapp(request):
    if request.META['QUERY_STRING']:
        #... start scripts etc..
        request.META['QUERY_STRING'] = False

        return controlpanel(request)  

the function return controlpanel with query string... (127.0.0.1:8000/startapp?run=True but I only want 127.0.0.1:8000/controlpanel)

controlpanel.html

<div>
{% if active %}
 <button onclick="f()" class="btn btn-md btn-success">Start</button>
{% else %}
 <button onclick="f()" class="btn btn-md btn-warning">Start</button>
{% endif %}
</div>


<script>
function f() {
let a = null;
if ('{{active}}' === 'True') {
  a = 'stop'
} else {
  a = 'start'
}
window.location.href = "/startapp?run=" + a;            
}
</script>

1 Answer 1

1

You could use Django's redirect to return the URL without the query parameters.

Sign up to request clarification or add additional context in comments.

Comments

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.