1

I have a script that i run from command to populate a django model from csv.. the command i use is:

python artifact_db_loader.py -tzusb "d:\Test_Data\david nides\david-nides-usb.csv" -e 44

I want to change this so that it can be run on a django view on page request. Anyone with an insight please? Regards, Josh

4
  • simple . artifact_db_loader.py add this file to project root dir . make new function that accepts your arguments . call it from django view . Commented Mar 14, 2014 at 7:12
  • Priyank Please give more guidelines on this..I can give you more details Commented Mar 15, 2014 at 15:22
  • Django has a whole section in their documentation explaining how to do it. Did you read the doc? Commented Mar 16, 2014 at 10:32
  • point me to the doc you referring to Bibhas Commented Mar 16, 2014 at 23:28

2 Answers 2

1

From my experience you can do anything you would do on a regular python script inside a Django view. For example :

#! python3
# -*-coding:utf-8 -*

from django.shortcuts import HttpResponse
import os

def myView(request):
    f = open('file.cvs', 'w')
    f.write('Whatever you want')
    f.close()
return HttpResponse('Done.')

You can put conditions and loops, so you should be able to put your entire script as a view like that.

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

Comments

1

As you haven't provided any details about the script, I'm assuming there is a function inside that takes the filename and a model name as parameters and does the work when invoked from the terminal. You can simply move that function to a controller and call it with both the parameters on request.

Django has a whole section in their documentation explaining how to do it.

1 Comment

the link is broken.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.