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

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

问题描述

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

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_Datadavid nidesdavid-nides-usb.csv" -e 44

我想更改此设置,以便它可以在页面请求时在 Django 视图上运行.请问有知情者吗?问候,乔希

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

推荐答案

由于您尚未提供有关脚本的任何详细信息,因此我假设内部有一个函数将文件名和模型名作为参数并执行从终端调用时的工作.您可以简单地将该函数移动到控制器,并根据请求使用两个参数调用它.

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天全站免登陆