# run a script with an html button

**URL:** <https://forum.djangoproject.com/t/run-a-script-with-an-html-button/5445>\
**Category:** Using Django\
**Created:** [November 29, 2020, 1:31pm UTC](https://forum.djangoproject.com/t/run-a-script-with-an-html-button/5445 "2020-11-29T13:31:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Minuke](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/minuke/32/2604_2.png) [@Minuke](https://forum.djangoproject.com/u/Minuke)\
**Post date:** [November 29, 2020, 1:31pm UTC](https://forum.djangoproject.com/t/run-a-script-with-an-html-button/5445/1 "2020-11-29T13:31:06Z")

</div>

Hi, I’m trying to run a script that generates a .csv file when you click a button but I don’t know how to do it. my work directory is as follows:

 ![work_directory](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/1/1c42f01140341da8ea10102d6e79794f60b41a7c.png)

my html in ‘templates’home.html’:

```
<form action = "script/one.py" method = "POST">

    <input type = "submit" value = "articulos">

</form>

```

my script.py in 'script/one.py:

```
import pandas as pd

cat = "adios"

print(cat) 

```

my view in /articulos/view.py:

```
from django.shortcuts import render

from django.views.generic import ListView

from .models import Articulo

class ArticuloListView(ListView):

    model = Articulo

    template_name = 'home.html'

    import os

    os.system('python script/one.py')

```

I use os.system to call the script and it gets into it but when I import the “pandas” library to create .csv files I get the following error:

> Performing system checks…
> 
> Traceback (most recent call last):  
> File “C:\Users\Minuke\Desktop\prueba\script\one.py”, line 1, in   
> import pandas as pd  
> ModuleNotFoundError: No module named ‘pandas’  
> System check identified no issues (0 silenced).  
> November 29, 2020 - 13:50:22  
> Django version 3.1, using settings ‘config.settings’  
> Starting development server at [http://127.0.0.1:8000/](http://127.0.0.1:8000/)  
> Quit the server with CTRL-BREAK.

and this happens with any import, I don’t know very well how to do to run a script completely using django

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [November 29, 2020, 2:39pm UTC](https://forum.djangoproject.com/t/run-a-script-with-an-html-button/5445/2 "2020-11-29T14:39:23Z")

</div>

It appears that the basic issue is that your environment isn’t properly set up when trying to run it. But I have to wonder why you’re trying to run this as an external script rather than just putting the work you’re really trying perform in your view (or a function that the view calls).

---

<div class="post-metadata">

**Author:** ![Minuke](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/minuke/32/2604_2.png) [@Minuke](https://forum.djangoproject.com/u/Minuke)\
**Post date:** [November 29, 2020, 3:21pm UTC](https://forum.djangoproject.com/t/run-a-script-with-an-html-button/5445/3 "2020-11-29T15:21:42Z")

</div>

I forget to import the “pandas” library for my virtual environment, sorry i’m new to django
