title: in which file is it best to call celery task?
body: <p>I have a celery task that uses <code>send_mail</code> to send an email notification to a User after they create an account.</p>
  <pre><code>from celery import shared_task
  from celery.utils.log import get_task_logger
  from django.core.mail import send_mail
  from my_group.settings import NOTIFICATION_EMAIL
  
  logger = get_task_logger(__name__)
  
  @shared_task(name='registration_notification_task')
  def registration_notification_task(email):
      logger.info('sent registration email')
      send_mail(
                  'Welcome!',
                  'Message',
                  NOTIFICATION_EMAIL,
                  [email],
                  fail_silently=True
              )
  </code></pre>
  <p>It takes in one argument of <code>email</code> and is called in my UserRegistration view:</p>
  <pre><code>class UserRegistration(generic.CreateView):
      form_class = RegisterForm
      template_name = 'registration/registration.html'
      success_url = reverse_lazy('home')
  
      def form_valid(self, form):
          user = form.save()
          form.registration_notification()
          login(self.request, user, backend='django.contrib.auth.backends.ModelBackend')
          return redirect(self.success_url)
  </code></pre>
  <p><code>registration_notification()</code> is defined in my RegisterForm here:</p>
  <pre><code>class RegisterForm(UserCreationForm):
      email = forms.EmailField()
      first_name = forms.CharField(max_length=100)
      last_name = forms.CharField(max_length=100)
  
      class Meta:
          model = User
          fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2')
  
      def registration_notification(self):
          email = self.cleaned_data['email']
          if self.is_valid():
              registration_notification_task.delay(email)
  </code></pre>
  <p>My question is whether it's better to call the task in the form when <code>is_valid()</code> or if it's better to just call the task directly in the view in <code>def form_valid()</code>? Is there a difference where the task is called?</p>
  <p>Another reason I ask this is because it's easier for me to have the tasks be called in the views instead of passing arguments over to the form. Some tasks I want to run involve objects and when I try and pass instance from <code>instance = form.save()</code> into my form I get an error that object is not JSON serializable.</p>
  <p>I've found ways around that, but I still want to know the preferred method for task placement. I'd personally rather always call them in the view if possible.</p>