title: In Django I use request.POST and return JSONResponse but the url shows HttpResponse object error. I don't want to use render()
body: <p>I'm using Ajax to submit a POST. In views.py I have the following:</p>
  <pre><code>def color(request):
      if(request.POST.get('mydata',False)):
          mylist= request.POST['mydata']
          mylist= mylist.split(&quot;,&quot;)
          request.session['var1'] = mylist[0]
          request.session['var2'] = mylist[1]
          return JsonResponse({'success':True})
  </code></pre>
  <p>In <code>urls.py</code> I defined <code>color</code>, so when I go to <code>localhost:8000/color</code> it shows error: &quot;<code>didn't return an HttpResponse object</code>&quot;. I should use instead <code>return render(request,'app/color.html',{})</code> but I do not have a <code>color.html</code> file. I actually don't want to have one. All I want is to post a variable and use it as a session, so how can I avoid using render() and creating the html file? Thanks</p>
  <p><strong>EDIT</strong>: add ajax</p>
  <pre><code>list=['black','white']
  $.ajax({
         type: &quot;POST&quot;,
         url: '/color/',
         data: {
           'mydata': list.join(&quot;,&quot;),
           'csrfmiddlewaretoken': '{{ csrf_token }}'
         },
         dataType: &quot;json&quot;,
         success: function (data) {
           alert(&quot;it worked!&quot;);
         },
         error: function (data) {
           alert(&quot;it did not work&quot;);
         }
  })
  </code></pre>