I have the following view:
def addtolist(request):
var1 = request.session.get('session_pmids', False)
pmids = request.POST.get('pmids', '')
pmids = pmids.split(",")
if var1:
pmids = pmids + var1
request.session["session_pmids"] = pmids
if not var1:
request.session["session_pmids"] = pmids
return HttpResponse(None, request)
and in the template I have the following:
<form id="go" action="/addtolist/" method="post" data_url>{% csrf_token %}
<input type="hidden" name="pmids" id="pmids" value="">
<button class = "btn btn-default" onclick="getChecked()">Get selected abstracts as reference</button>
</form>
The button press will retrieve some data via the getChecked() function. which will add data to the input box 'pmids'. These will be cast to the view and the variables will be added to the session.
How can I let Django return nothing from the view? so, no new page, no reload. Only the request object (to keep the session)