title: unable to return json from django view to axios
body: <p>I want to make a Visual search interface with keywords and category to search sth. Obviously, It needs front-end and back-end data interaction. So after weighing some tools, I have choosed <strong>Vue</strong> and <strong>axios</strong> to implement data interaction in the <strong>front-end</strong>, and <strong>django view</strong> in the <strong>front-end</strong>.</p>
  
  <p>In my index.html page, I defined my axios like this. </p>
  
  <pre><code>var param = new URLSearchParams();
  param.append('searchKey',this.searchKey);
  param.append('category',this.selected);
  
  axios.post("{% url 'main:getCommodityInfo'%}",
               param,
              {headers:{'X-CSRFToken': this.getCookie('csrftoken')}},)
       .then(response=&gt;{
             console.log(response);
        })
       .catch(error=&gt;{
             console.log(error);
             alert("connection has error")
        })
  </code></pre>
  
  <p><strong>searchKey</strong> and <strong>category</strong> could be acquired by Vue object. Then I post the data to my back-end django view.</p>
  
  <pre><code>def getCommodityInfo(request):
      if request.method=="POST":
          # To get the POST paramaters
          searchKey = request.POST.get('searchKey')
          category = request.POST.get('category')
          # unique ID for each record for DB
          uniqueId = str(uuid4())
          print("Enter the view!  ",searchKey,category)
          # set setting
          settings = {
              'unique_id': uniqueId,  
              'USER_AGENT': 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
          }
          # task Id to indentify each spider task
          task = scrapyd.schedule('JDSpider', 'getCommodityInfo',
                                  settings=settings, searchKey=searchKey, category=category)
  
          print("It seems everything is running well? ")
          print(task,uniqueId)
          print("-"*100)
          return JsonResponse({'taskId': task, 'uniqueId': uniqueId, 'status': 'started'},safe=False)
  </code></pre>
  
  <p>Well, the view could acutally get the POST paramaters. <strong><em>But When I am trying to return the status json from view to the axios function, error occurs.</em></strong> </p>
  
  <pre><code>[20/Mar/2019 21:03:08] "GET /main/ HTTP/1.1" 200 7216
  [20/Mar/2019 21:03:08] "GET /static/main/axios.min.js HTTP/1.1" 304 0
  [20/Mar/2019 21:03:08] "GET /static/main/axios.min.map HTTP/1.1" 304 0
  Enter the view!   switch Electronics
  [20/Mar/2019 21:03:30] "GET /main/?searchKey=switch&amp;category=Electronics HTTP/1.1" 200 7216
  It seems everything is running well? 
  8fdcee984b1011e9b7e5ace010528bab e07cd1ee-efe8-4c23-8457-51732aa57435
  ----------------------------------------------------------------------------------------------------
  [20/Mar/2019 21:03:33] "POST /main/getCommodityInfo/ HTTP/1.1" 200 119
  Traceback (most recent call last):
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 138, in run
      self.finish_response()
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 180, in finish_response
      self.write(data)
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 274, in write
      self.send_headers()
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 332, in send_headers
      self.send_preamble()
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 255, in send_preamble
      ('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 453, in _write
      result = self.stdout.write(data)
    File "D:\Anacaonda\lib\socketserver.py", line 775, in write
      self._sock.sendall(b)
  ConnectionAbortedError: [WinError 10053] The software in your host has aborted an established connection.
  [20/Mar/2019 21:03:33] "POST /main/getCommodityInfo/ HTTP/1.1" 500 59
  ----------------------------------------
  Exception happened during processing of request from ('127.0.0.1', 11890)
  Traceback (most recent call last):
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 138, in run
      self.finish_response()
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 180, in finish_response
      self.write(data)
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 274, in write
      self.send_headers()
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 332, in send_headers
      self.send_preamble()
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 255, in send_preamble
      ('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 453, in _write
      result = self.stdout.write(data)
    File "D:\Anacaonda\lib\socketserver.py", line 775, in write
      self._sock.sendall(b)
  ConnectionAbortedError: [WinError 10053] The software in your host has aborted an established connection.
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 141, in run
      self.handle_error()
    File "D:\Anacaonda\lib\site-packages\django\core\servers\basehttp.py", line 86, in handle_error
      super().handle_error()
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 368, in handle_error
      self.finish_response()
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 180, in finish_response
      self.write(data)
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 274, in write
      self.send_headers()
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 331, in send_headers
      if not self.origin_server or self.client_is_modern():
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 344, in client_is_modern
      return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
  TypeError: 'NoneType' object is not subscriptable
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "D:\Anacaonda\lib\socketserver.py", line 639, in process_request_thread
      self.finish_request(request, client_address)
    File "D:\Anacaonda\lib\socketserver.py", line 361, in finish_request
      self.RequestHandlerClass(request, client_address, self)
    File "D:\Anacaonda\lib\socketserver.py", line 696, in __init__
      self.handle()
    File "D:\Anacaonda\lib\site-packages\django\core\servers\basehttp.py", line 154, in handle
      handler.run(self.server.get_app())
    File "D:\Anacaonda\lib\wsgiref\handlers.py", line 144, in run
      self.close()
    File "D:\Anacaonda\lib\wsgiref\simple_server.py", line 35, in close
      self.status.split(' ',1)[0], self.bytes_sent
  AttributeError: 'NoneType' object has no attribute 'split'
  </code></pre>
  
  <p>I have tried to debug the process, but the code logic is too complicated to understand. <strong><em>I could only find the errors happens when executing</em></strong> </p>
  
  <pre><code>return JsonResponse({'taskId': task, 'uniqueId': uniqueId, 'status': 'started'},safe=False)
  </code></pre>
  
  <p>I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this.Thanks in advance.</p>
  
  <hr>
  
  <p>I' ve looked around and apparently I've got the choice below.</p>
  
  <pre><code>&lt;form  action="{%url 'main:getCommodityInfo'%}" method="POST"&gt;
  </code></pre>
  
  <p>Using the form could get the json from the django View after my test. But I don't want to use it in my project instead of axios.</p>