Добавление сокетов в Django View для контакта с роботом
Я пытаюсь давать команды роботу с сайта на Django через сокеты, так как это было рекомендовано как лучший возможный способ сделать это. Я работал с Django и сокетами по отдельности, но мне не удалось найти подходящий учебник (только чат-приложения) о том, как интегрировать эти два компонента. Если у кого-то есть опыт в этом и он знает, как добавить это к моему представлению, любая помощь была бы замечательной. (Мне просто нужна помощь с серверной стороной, я знаю, как настроить клиента)
Моя модель:
class Robot(models.Model):
def fetch_choices():
scope = [REDACTED]
creds = ServiceAccountCredentials.from_json_keyfile_name("dashboard/Files/creds.json", scope)
client = gspread.authorize(creds)
sheet = client.open("tutorial").sheet1
path_names = []
path_name_fetch = sheet.col_values(1)
for i in path_name_fetch:
if (i, i) not in path_names:
path_names.append((i, i))
return path_names
name = models.CharField(max_length=200)
path_options = models.CharField(choices=fetch_choices(), default=fetch_choices(), max_length=100)
status_choices = [('waiting', 'waiting'), ('running', 'running'), ('stuck', 'stuck')]
current_status = models.CharField(choices=status_choices, default=status_choices[0], max_length=100)
def __str__(self):
return self.name + ' | Current Status: ' + self.current_status
def get_absolute_url(self):
return reverse('dashboard-home')
Моя форма:
class RobotDetail(UpdateView):
model = Robot
form_class = RobotUpdateForm
template_name = 'dashboard/robotdetail.html'
Мой шаблон:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dashboard</title>
</head>
<body>
{% extends 'theblog/base.html' %}
{% block content %}
<h1>Dispatcher</h1>
<form method="POST">
{% csrf_token %}
{{ form.as_p}}
<button class="btn btn-secondary">Dispatch</button>
</form>
{% endblock %}
</body>
</html>