更改脚本从命令行运行到django视图 [英] Change script run from commandline to django view

查看:102
本文介绍了更改脚本从命令行运行到django视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,我从命令运行从csv ..填充django模型。$ ​​b $ b我使用的命令是:

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

我想改变它,以便它可以在页面请求上的django视图上运行。
任何有洞察力的人?
Regards,
Josh

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

推荐答案

由于您没有提供有关脚本的任何详细信息, m假设有一个函数里面的文件名和模型名称作为参数,并从终端调用时的工作。您可以简单地将该函数移动到控制器,并根据请求使用这两个参数调用它。

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有一个整个部分中解释如何执行。

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

这篇关于更改脚本从命令行运行到django视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆