title: Django Celery send register email do not work
body: <p>I am learning Celery. In my website, I let people register an account. Once they create a new account, it will automatically send an activation email to their user email address.</p>
  
  <p>Everything works well but now I want to use Celery to send the email asynchronously.</p>
  
  <p>I use RabbitMQ as broker, version 3.1.5 and Celery 3.1.7 (the latest version), as they say this version does not need djcelery. So all I need is just to install Celery.</p>
  
  <p>I followed the instruction as celery its website, Configurate my django.</p>
  
  <pre><code>proj
    --proj/celery.py
  </code></pre>
  
  <p>Here is my <strong>celery.py</strong>:</p>
  
  <pre><code>from __future__ import absolute_import
  
  import os
  
  from celery import Celery
  
  from django.conf import settings
  
  # set the default Django settings module for the 'celery' program.
  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
  
  app = Celery('proj')
  
  # Using a string here means the worker will not have to
  # pickle the object when using Windows.
  app.config_from_object('django.conf:settings')
  app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
  
  @app.task(bind=True)
  def debug_task(self):
      print('Request:{0!r}'.format(self.request))
  </code></pre>
  
  <p>And this is the <strong>tasks.py</strong> that I put in my app folder:</p>
  
  <pre><code>proj
   ---proj/celery.py
   ---app/tasks.py
  </code></pre>
  
  <p><strong>tasks.py</strong></p>
  
  <pre><code>from __future__ import absolute_import
  
  from celery.decorators import task
  
  @task()
  def user_send_activation_email(user):
      user.send_activation_email()
  </code></pre>
  
  <p>I added the <code>send_activation_email</code> function to user models, so user can send the email.</p>
  
  <p>This is my <strong>views.py</strong>:</p>
  
  <pre><code>from django.shortcuts import render_to_response, redirect,render
  from django.conf import settings
  from django.http import HttpResponse,HttpResponseRedirect,Http404
  from django.template import RequestContext
  from app.accounts.forms import SignupForm
  from django.contrib.auth import get_user_model
  from app.sns_utils import generate_sha1 
  from app.tasks import user_send_activation_email 
  
  def signup(request):
      if request.method=='POST':
          form=SignupForm(data=request.POST)
          if form.is_valid():
              UserModel=get_user_model()
              username = form.cleaned_data['username']
              email = form.cleaned_data['email']
              password = form.cleaned_data['password']
               user=UserModel.objects.create_user(username=username,email=email,password=password)
              user.activation_key = generate_sha1(username)
              user.save()
              user_send_activation_email.delay(user=user)
  
  
              return redirect('/')
  </code></pre>
  
  <p>And here is how I configured Celery in <strong>settings.py</strong>:</p>
  
  <pre><code>BROKER_URL = 'amqp://guest:guest@localhost:5672//'
  
  CELERY_RESULT_BACKEND = 'amqp://guest:guest@localhost:5672//'
  
  CELERY_TASK_SERIALIZER = 'json'
  </code></pre>
  
  <p>everything just follow celery its website say.</p>
  
  <p>Once I <code>manage.py runserver</code>, in the signup page, I register a new account with username  <code>vmuser630</code>, and it shows this error:</p>
  
  <pre><code>EncodeError at /accounts/signup/
  &lt;MyUser: vmuser630&gt; is not JSON serializable
  Request Method: POST
  Request URL:    http://localhost:8000/accounts/signup/
  Django Version: 1.6
  Exception Type: EncodeError
  Exception Value:    
  &lt;MyUser: vmuser630&gt; is not JSON serializable
  Exception Location: C:\Python33\lib\json\encoder.py in default, line 173
  Python Executable:  C:\Python33\python.exe
  Python Version: 3.3.2
  </code></pre>
  
  <p>If I remove this from <strong>settings.py</strong>:</p>
  
  <pre><code>CELERY_TASK_SERIALIZER = 'json'
  </code></pre>
  
  <p>and try again <code>manage.py runserver</code>, I'm just redirected to the '/' page. The new account is in the database, but I did not get the activation email.</p>
  
  <p>It looks like the send email task has just been passed, nothing happened.</p>
  
  <p>When i change the send email function back to:</p>
  
  <pre><code>user.send_activation_email()
  </code></pre>
  
  <p>it means I do not user celery, it works, I can get the activation email.</p>
  
  <p>Why does it show the error <strong>not  JSON serializable</strong>?</p>