0

I added some python file in my django project but that python file did not execute. How can i run that python scrip in django.

2
  • What do you mean by "did not execute"? Also you mean using it e.g. in a Django view, or do you mean run a script independently while having access to the Django environment like the database? Commented Jun 24, 2015 at 17:50
  • @bakkal i want to run indivisually on background...i want to process some data on backgroung and update.....but in django project.....means when i start django server i want that script to start....... Commented Jun 24, 2015 at 17:53

1 Answer 1

1

OK it seems you want to run a script outside of the HTTP request/response cycle, I'd recommend you make a Django admin command, because a script will need to e.g. have access to the database environment to update records

from django.core.management.base import BaseCommand
from yourapp.models import Thing
import your_script

class Command(BaseCommand):
    help = 'Closes the specified poll for voting'

    def handle(self, *args, **options):
        # Do your processing here
        your_script.process(Thing.objects.all())

With this you can call ./manage.py process_thing and it'll run independently

More on Django admin commands here, https://docs.djangoproject.com/en/1.8/howto/custom-management-commands/

If the processing is triggered programmatically e.g. from user requests, you'll have to setup a queue and have a task job created for each request, I'd try Celery, more on that here http://celery.readthedocs.org/en/latest/django/first-steps-with-django.html

Sign up to request clarification or add additional context in comments.

1 Comment

actually i am trying to load json fixture through python script and this json file i am getting through server.....so here i am continuously listening to server and if any update in json data i am updating through fixtures...for this purpose in need to run script which do all this task....and i want to do this in django project....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.