P
P
PtrGrd2022-04-11 18:22:05
Python
PtrGrd, 2022-04-11 18:22:05

How to make a web interface for managing a script?

Hello. Tell me how best to do it. What we have: a project written in Python, as well as deployed on a separate server and the desire to manage this project, manipulating its settings and passing input data, files straight from the browser window. We need advice on how best to implement this so that it is safe (without access to the system by unauthorized persons). Variants of Django-admin panel, self-written analogue, CGI were considered.
Thanks everyone for the replies.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav Samoilov, 2022-04-11
@PtrGrd

several options:
1. Django - convenient, understandable, easy to work with. Own structure and template engine. In any case, you work through a bunch of BackEnd - Front
2. Flask is lightweight, simple, easy to work with. the benefits are almost the same as with Django
3. JS - What difference does it make, through which language to send data to Back python? Easy. There is no need to use a template engine. Honestly takes and sends data from the front to the Backend and takes the response back from the back. just for your script. Lots of examples of how this link works.
4. Html+Css form - without JS. Pure form. Other people will have access. But you can log in with a password without any problems.

Python form submission example without feedback
import requests
# Если нужны Header → from requests.structures import CaseInsensitiveDict

url = "https://qna.habr.com/q/1139382"

# Сюда вставляешь Headers, если надо.
# headers["Authorization"] = "PtrGrd"
# headers["Content-Type"] = "application/Chrome, например. Или что там пишется"

data = "name=PtrGrd&password=qwerty123&yetanother=123"


resultat = requests.post(url, headers=headers, data=data)

print(resultat.status_code)

If you keep it on the local machine, it makes sense to run only js or html.
On the server - access through authorization to the script. And manage your script through the form. This is the easiest and fastest.
If you know Flask or Django, you can use them too. But won't you make the project heavier? We would have goals and scope. Or maybe you need Vue.js
If you need to get "feedback", then use Flask.
Here is an example:
Html:
<html> <!-- index.html -->
<body>
    <p>Время срабатывания скрипта: {{ time_to_start }} секунд</p>
</body>
</html>

Python:
from flask import Flask, render_template

app = Flask('Mega')

@app.route('/')
def index():
    tts = 60
    return render_template('index.html', time_to_start=tts)

if __name__ == '__main__':
    app.run()

E
Elvis, 2022-04-11
@Dr_Elvis

IMHO Flask for this is much easier, shorter and faster to write.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question