Hello.
I am fairly new to Django. Basically, I have a python script which translates text from a language to English. The file containing the text will be .csv or .tsv and user can upload that file for which I have a form.
Now when the user uploads the file and presses the “Translate” button, I want Python (not JavaScript/JQuery/AJAX template) to handle it.
Now I am aware of views and rendering and redirecting etc. But basically I’m not aware of options to connect a Python script/view with an HTML button click.
The folder structure for the project is as under:
The translate.py contains the module responsible for translating the text/data. I call the concerned function in a view but I don’t know how I can trigger the view once the user will click the HTML button (whose type is “submit”).
Also, I would like that once the file has been uploaded and translate button has been pressed, some spinner or progress bar is displayed whose width (or percentage) values are updated continuously depending upon how much the file has been translated.
Lastly, I want that translated file to be available for the user to download.
The HTML right now is:
<<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Translate data to English</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</head>
<body>
<div class="col-md-6 offset-md-3 mt-5">
<form accept-charset="UTF-8" method="POST" enctype="multipart/form-data" target="_blank">
{% csrf_token %}
<div class="form-group">
<label for="exampleInputName">Full Name</label>
<input type="text" name="fullname" class="form-control" id="exampleInputName" placeholder="Enter your name and surname" required="required">
</div>
<div class="form-group">
<label for="exampleInputEmail1" required="required">Email address</label>
<input type="email" name="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Favourite Platform</label>
<select class="form-control" id="exampleFormControlSelect1" name="platform" required="required">
<option>CSV</option>
<option>TSV</option>
</select>
</div>
<hr>
<div class="form-group mt-3">
<label class="mr-2"> <h6> Upload the file which you want to get translated: </h6> </label>
<input type="file" name="file">
</div>
<hr>
<button type="submit" class="btn btn-primary">Translate</button>
</form>
</div>
</body>
</html>