title: Run Celery Worker from FLASK app
body: <p>I'm making an app in FLASK and I've incorporated Celery into it. However, I have to run the app via the terminal if I want the Celery worker to work as well. (<code>celery -A app.celery worker</code>). I tried running it from the main <code>run.py</code> file as follows</p>
  
  <p>init.py </p>
  
  <pre><code>from flask import Flask
  from flask.ext.sqlalchemy import SQLAlchemy
  from flask.ext.mail import Mail
  from celery import Celery
  from kombu import serialization
  
  
  app = Flask(__name__)
  app.config.from_object('config')
  db = SQLAlchemy(app)
  mail = Mail(app)
  app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
  app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
  app.config['CELERY_ACCEPT_CONTENT'] = ['json']
  app.config['CELERY_TASK_SERIALIZER'] = 'json'
  app.config['CELERY_RESULT_SERIALIZER'] = 'json'
  celery = Celery(app.name, broker=app.config['CELERY_BROKER_URL'])
  celery.conf.update(app.config)
  serialization.registry._decoders.pop("application/x-python-serialize")
  
  from app import views
  </code></pre>
  
  <p>and run.py</p>
  
  <pre><code>#!flask/bin/python
  from __future__ import absolute_import, unicode_literals
  from app import app
  # app.run(debug=True, port=9001)
  
  from celery import current_app    
  from celery.bin import worker
  
  app = current_app._get_current_object()
  
  worker = worker.worker(app=app)
  
  options = {
      'broker': app.config['CELERY_BROKER_URL'],
      'loglevel': 'INFO',
      'traceback': True,
  }
  
  worker.run(**options)
  </code></pre>
  
  <p>But this gives the error <code>AttributeError: 'Celery' object has no attribute 'config'</code></p>
  
  <p>Any pointers as to what Im doing wrong would be much appreciated. </p>