when trying to run celery local I get an error message
<p>This is my file structure</p>

<pre><code>venv/
 |-src/
   |-gettingstarted/
   |  |-settings/
   |     |-__init__.py
   |     |-base.py
   |     |-local.py
   |     |-production.py
   |
   |-blog/
   |  |-__init__.py
   |  |-admin.py
   |  |-forms.py
   |  |-models.py
   |  |-tasks.py
   |  |-urls.py
   |  |-views.py
   |
   |-manage.py
</code></pre>

<p>my views.py</p>

<pre><code>from .tasks import add, p_panties

def shopan(request):
    # one = scrape_and_store_world()
    # two = panties()
    # argument_scrapes(one, two)
    p_panties.delay()
    return redirect('/')
</code></pre>

<p>my tasks.py</p>

<pre><code>import requests
import random
import re
import os

from celery import Celery
from bs4 import BeautifulSoup


app = Celery('tasks', backend='redis://localhost', broker='redis://localhost')


@app.task
def add(x, y):
    return x + y


@app.task
def reverse(string):
    return string[::-1]


@app.task
def p_panties():
    def swappo():
        user_one = ' "Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0" '
        user_two = ' "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)" '
        user_thr = ' "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko" '
        user_for = ' "Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:10.0) Gecko/20100101 Firefox/10.0" '

        agent_list = [user_one, user_two, user_thr, user_for]
        a = random.choice(agent_list)
        return a

    headers = {
        "user-agent": swappo(),
        "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
        "accept-charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.3",
        "accept-encoding": "gzip,deflate,sdch",
        "accept-language": "en-US,en;q=0.8",
    }

    pan_url = 'http://www.example.com'
    shtml = requests.get(pan_url, headers=headers)
    soup = BeautifulSoup(shtml.text, 'html5lib')
    video_row = soup.find_all('div', {'class': 'post-start'})
    name = 'pan videos'



    def youtube_link(url):
        youtube_page = requests.get(url, headers=headers)
        soupdata = BeautifulSoup(youtube_page.text, 'html5lib')
        video_row = soupdata.find_all('p')[0]
        entries = [{'text': div,
                    } for div in video_row]
        tubby = str(entries[0]['text'])
        urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&amp;+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', tubby)
        cleaned_url = urls[0].replace('?&amp;amp;autoplay=1', '')
        return cleaned_url

    def yt_id(code):
        the_id = code
        youtube_id = the_id.replace('https://www.example.com/embed/', '')
        return youtube_id

    def strip_hd(hd, move):
        str = hd
        new_hd = str.replace(move, '')
        return new_hd

    entries = [{'href': div.a.get('href'),
                'text': strip_hd(strip_hd(div.h2.text, 'â Official video HD'), 'â Oficial video HD').lstrip(),
                'embed': youtube_link(div.a.get('href')), #embed
                'comments': strip_hd(strip_hd(div.h2.text, 'â Official video HD'), 'â Oficial video HD').lstrip(),
                'src': 'https://i.ytimg.com/vi/' + yt_id(youtube_link(div.a.get('href'))) + '/maxresdefault.jpg', #image
                'name': name,
                'url': div.a.get('href'),
                # 'author': author,
                'video': True

                } for div in video_row][:13]

    return entries
</code></pre>

<p>in my terminal  </p>

<pre><code>(practice) apples-MBP:blog ray$ celery worker -A tasks -l info 
[2016-09-14 11:30:14,537: WARNING/MainProcess] /Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/celery/apps/worker.py:161: CDeprecationWarning: 
Starting from version 3.2 Celery will refuse to accept pickle by default.

The pickle serializer is a security concern as it may give attackers
the ability to execute any command.  It's important to secure
your broker from unauthorized access when using pickle, so we think
that enabling pickle should require a deliberate action and not be
the default choice.

If you depend on pickle then you should set a setting to disable this
warning and to be sure that everything will continue working
when you upgrade to Celery 3.2::

    CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml']

You must only enable the serializers that you will actually use.


  warnings.warn(CDeprecationWarning(W_PICKLE_DEPRECATED))

 -------------- celery@apples-MBP.fios-router.home v3.1.23 (Cipater)
---- **** ----- 
--- * ***  * -- Darwin-15.6.0-x86_64-i386-64bit
-- * - **** --- 
- ** ---------- [config]
- ** ---------- .&gt; app:         tasks:0x1037836a0
- ** ---------- .&gt; transport:   redis://localhost:6379//
- ** ---------- .&gt; results:     redis://localhost/
- *** --- * --- .&gt; concurrency: 4 (prefork)
-- ******* ---- 
--- ***** ----- [queues]
 -------------- .&gt; celery           exchange=celery(direct) key=celery


[tasks]
  . tasks.add
  . tasks.p_panties
  . tasks.reverse

[2016-09-14 11:30:14,689: INFO/MainProcess] Connected to redis://localhost:6379//
[2016-09-14 11:30:14,702: INFO/MainProcess] mingle: searching for neighbors
[2016-09-14 11:30:15,710: INFO/MainProcess] mingle: all alone
[2016-09-14 11:30:15,723: WARNING/MainProcess] celery@apples-MBP.fios-router.home ready.
</code></pre>

<p>when I try to run my my program this error message I get is</p>

<pre><code>[2016-09-14 11:30:32,171: ERROR/MainProcess] Received unregistered task of type 'blog.tasks.p_panties'.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see 
</code></pre>

<p><a href="http://docs.celeryq.org/en/latest/userguide/tasks.html#task-names" rel="nofollow">here</a> for more information.</p>

<pre><code>The full contents of the message body was:
{'timelimit': (None, None), 'task': 'blog.tasks.p_panties', 'chord': None, 'taskset': None, 'errbacks': None, 'id': 'd9814eb1-98a9-4b45-b049-e36ac64fc55c', 'retries': 0, 'args': [], 'utc': True, 'expires': None, 'eta': None, 'kwargs': {}, 'callbacks': None} (263b)
Traceback (most recent call last):
  File "/Users/ray/Desktop/myheroku/practice/lib/python3.5/site-packages/celery/worker/consumer.py", line 456, in on_task_received
    strategies[name](message, body,
KeyError: 'blog.tasks.p_panties'
</code></pre>

<p>Am I supposed to make this an app so I can use it?</p>

<h1>EDIT</h1>

<p>my blog/celery.py as you suggested me to write it</p>

<pre><code>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', 'gettingstarted.settings'
)

app = Celery('tasks')

# 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)
</code></pre>

<p>How I run the celery worker</p>

<pre><code>celery worker -A tasks -l info
</code></pre>

<p>and I'm running it in the blog directory because that's where the tasks.py is, else If I run in src I get </p>

<pre><code>No module named 'tasks'
</code></pre>

<p>but If I run it in src I get</p>

<pre><code>Parent module '' not loaded, cannot perform relative import
</code></pre>

<p>You're getting a long warning, telling you not to use <em>pickle</em> in case <a href="http://docs.celeryproject.org/en/latest/faq.html#isn-t-using-pickle-a-security-concern" rel="nofollow">you're not familiar with it's possible side effects</a>. So it's better to set celery serializer to use json.</p>

<pre><code>CELERY_TASK_SERIALIZER = 'json'
</code></pre>

<p>Now to the main problem, the task that's being run is, as the error indicates, <strong>blog.tasks.p_panties</strong>, But as the output of running celery worker indicates, the task that's registered with celery, is <strong>tasks.p_panties</strong>.</p>

<p>The problem is arising since you're creating the celery app instance, inside your <strong>tasks.py</strong>, so it's registering tasks with names like <strong>task.*</strong>.</p>

<p>The solution to this is to create a <em>celery.py</em> in your root directory and setup the celery app there and then finally, import that app object into your tasks.py file.</p>

<p>the contents of the celery.py would be like the following:</p>

<pre><code>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', DEFAULT_SETTINGS_MODULE
)

app = Celery('app_name')

# 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)
</code></pre>

<p>and then in your tasks.py, import it like below:</p>

<pre><code>from blog.celery import app
</code></pre>

<p>As can be seen, in the <strong>celery.py</strong> file, I've instantiated celery, and called <code>app.config_from_object('django.conf:settings')</code>. This way celery knows to read its configuration parameters from your django settings file. So all celery settings, would go there, including <code>BROKER_URL</code> and other settings (that you're passing directly to the celery object) </p>

<p><strong>Edit</strong></p>

<p>And don't run celery like : <code>celery worker -A tasks -l info</code> </p>

<p>run it like : <code>celery worker -A project_name -l info</code></p>

python django celery relativelayout file-structure