Я хочу запускать мой python файл при нажатии кнопки html. Когда я нажимаю run
в PyCharm, у меня работает файл python (он просто создает график). Мой файл python хранится как main.py
. У меня возникают проблемы с привязкой кнопки html для запуска файла main.py
при нажатии кнопки.
На данный момент я думаю, что у меня есть кнопка, указывающая на функцию в моем views.py
, которая, в свою очередь, запускает мой main.py
файл. (или я так думаю. Это не работает)
ИНДЕКС. HTML
<input type="button" value="Run graph" onclick="open('run_graph')">
URLS.PY
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name="index"),
path('run_graph', views.run_graph),
]
VIEWS.PY
def run_graph(main):
return main
ГЛАВНЫЙ.ПИ
import matplotlib.pyplot as plt
import numpy as np
col_count = 3
bar_width = .1
korea_scores = (554, 536, 538)
canada_scores = (518, 523, 525)
china_scores = (613, 570, 580)
france_scores = (495, 505, 499)
index = np.arange(col_count)
k1 = plt.bar(index, korea_scores, bar_width, alpha=.4, label="Korea")
c1 = plt.bar(index + bar_width, canada_scores, bar_width, alpha=.4, label="Canada")
ch1 = plt.bar(index + 0.2, china_scores, bar_width, alpha=.4, label="China")
f1 = plt.bar(index + 0.3, france_scores, bar_width, alpha=.4, label="france")
plt.ylabel("mean score in PISA 2012")
plt.xlabel("Subjects")
plt.title("France")
plt.xticks(index + .3 / 2, ('Maths', "Reading", "Science"))
plt.legend()
plt.grid(True)
plt.show()