Django get_object_or_404 is not defined
<p>I am developing a standalone application which uses ORM of django. In my main application, I am using django's module of get_object_or_404.</p>

<p>I have imported it with all its dependencies when I run the script, it gives me the error: </p>

<pre><code>Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/root/standAlone/tasks.py", line 48, in task1
NameError: global name 'get_object_or_404' is not defined
</code></pre>

<p>Here is my full script code:</p>

<pre><code>import django
from celery import Celery
from django.conf import settings
settings.configure(
    DATABASE_ENGINE    = "django.db.backends.mysql",
    DATABASE_NAME      = "database name",
    DATABASE_USER      = "username",
    DATABASE_PASSWORD  = "password",
    DATABASE_HOST      = "host",
    DATABASE_PORT      = "3306",
    INSTALLED_APPS     = ("myApp",)
)
django.setup()
from django.db import models
from myApp.models import *
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render,redirect
from django.shortcuts import get_list_or_404, get_object_or_404
from celery.decorators import task
from celery.utils.log import get_task_logger



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

@app.task(name="task1")
def task1(recipe_pk):
    recipe = get_object_or_404(Recipe, pk=recipe_pk) #error occurs here
    recipe.status = 'Completed'
    recipe.save()
</code></pre>

<p>Does anyone know how to solve this problem?</p>

<p>Try to remove this double import of "django.shortcuts".</p>

python django import