title: how to import celery tasks in django views
body: <p>I am learning celery with django. I am trying to create a simple addition project with django and celery. I created a simple webapp with django. in the index.html template, I have a form with 2 input fields. The first input field takes the <code>x value</code> (the first number for addition). The second input field takes <code>y value</code> (the second number for addition). When the form is submitted, I want the celery task to run. The django project name is <i><b>core</b></i> and the app name is <i><b>mainapp</b></i></p>
  <p>The celery task is as follows</p>
  <p><b>mainapp/tasks.py</b></p>
  <pre><code>from celery import Celery
  from celery.schedules import crontab
  from celery import shared_task
  
  @shared_task
  def add_num(x, y):
      return x+y
  </code></pre>
  <p><b>core/celery.py</b></p>
  <pre><code>from __future__ import absolute_import, unicode_literals
  import os
  from celery import Celery
  
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings')
  
  app = Celery('core')
  app.conf.timezone = 'UTC'
  app.config_from_object(&quot;django.conf:settings&quot;, namespace=&quot;CELERY&quot;)
  app.autodiscover_tasks()
  </code></pre>
  <p><b>mainapp/views.py</b></p>
  <pre><code>from django.shortcuts import render
  from . import tasks
  
  # Create your views here.
  def index(request):
      if request.method == 'POST':
          x = request.POST['x']
          y = request.POST['y']
  
          print(x, y)
  
          add_num.delay(x, y)
  
          return render(request, 'index.html')
  
      return render(request, 'index.html')
  </code></pre>
  <p>I have rabbitmq running in the background with the following command</p>
  <pre><code>brew services start rabbitmq
  </code></pre>
  <p>celery is running in a separate terminal window with the following command</p>
  <pre><code>celery -A core worker -B -l INFO
  </code></pre>
  <p>When I submit the form I get the following error.</p>
  <pre><code>NameError: name 'add_num' is not defined
  </code></pre>
  <p>I guess I am not importing the tasks into views.py properly.</p>