title: How can I post a variable from a python file to an html file in Django?
body: <p>I am trying to make a face recognition page using PyTorch.
  When the face is recognized, I want to go to the next page and print the name of the recognized person.</p>
  <p>I wrote the code, but on the next page, None is printed.
  In my terminal, &quot;POST / HTTP/1.1&quot; 200 532 is printed repeatedly
  sometimes &quot;GET /page HTTP/1.1&quot; 200 308 is printed.</p>
  <p>That is, I want to output the name and min_dist from the get_frame of camera2.py in the page.html file.</p>
  <p>(camera2.py) name, min_dist ---post---&gt;  (page.html) name, min_dist</p>
  <p>urls.py</p>
  <pre><code>from . import views
  
  urlpatterns = [
      path('', views.home, name='home'),
      path('detectme', views.detectme, name='detectme'),
      path('page', views.get_post, name='page')
  ]
  </code></pre>
  <p>views.py</p>
  <pre><code>from django.shortcuts import render
  from django.views.decorators import gzip
  from django.http import StreamingHttpResponse
  from detectme.camera2 import FaceDetect
  
  def home(request):
      return render(request, 'home.html')
  
  def gen(camera):
      while True:
          frame = camera.get_frame()
          yield(b'--frame\r\n'
                b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
  
  @gzip.gzip_page
  def detectme(request):
      return StreamingHttpResponse(gen(FaceDetect()), content_type=&quot;multipart/x-mixed-replace;boundary=frame&quot;)
  
  def check(request):
      return render(request, &quot;page.html&quot;)
  
  def get_post(request):
      if request.method == 'POST':
          student = request.POST.get('student')
          pred = request.POST.get('pred')
          data = {
              'name' : student,
              'pred' : pred
          }
          return render(request, 'page.html', data)
      
      if request.method == 'GET':
          student = request.POST.get('student')
          pred = request.POST.get('pred')
          data = {
              'name' : student,
              'pred' : pred
          }
          return render(request, 'page.html', data)
  </code></pre>
  <p>camera2.py</p>
  <pre><code>import cv2
  import threading
  import torch
  from facenet_pytorch import MTCNN, InceptionResnetV1
  from PIL import Image
  import requests
  
  font = cv2.FONT_HERSHEY_SIMPLEX
  mtcnn0 = MTCNN(image_size=240, margin=0, keep_all=False, min_face_size=40)
  mtcnn = MTCNN(image_size=240, margin=0, keep_all=True, min_face_size=40)
  resnet = InceptionResnetV1(pretrained='vggface2').eval()
  
  class FaceDetect(object):
      
      def __init__(self):
          self.video = cv2.VideoCapture(0)
          (self.grabbed, self.frame) = self.video.read()
          threading.Thread(target=self.update, args=()).start()
      
      def get_frame(self):
          load_data = torch.load('C:\coding\/face2\detectme\data.pt') 
          embedding_list = load_data[0] 
          name_list = load_data[1] 
          url = &quot;http://127.0.0.1:8000&quot;
          
          while True:
              frame = self.frame
              
              img = Image.fromarray(frame)
              img_cropped_list, prob_list = mtcnn(img, return_prob=True) 
              
              if img_cropped_list is not None:
                  boxes, _ = mtcnn.detect(img)
                          
                  for i, prob in enumerate(prob_list):
                      if prob&gt;0.90:
                          emb = resnet(img_cropped_list[i].unsqueeze(0)).detach() 
                          
                          dist_list = []
                          
                          for idx, emb_db in enumerate(embedding_list):
                              dist = torch.dist(emb, emb_db).item()
                              dist_list.append(dist)
  
                          min_dist = min(dist_list)
                          min_dist_idx = dist_list.index(min_dist)
                          name = name_list[min_dist_idx]
                          box = boxes[i] 
                          min_dist = round(min_dist, 3)
                          #original_frame = frame.copy()
                          
                          datas = {
                              'student' : name,
                              'pred' : min_dist
                          }
                          
                          response = requests.post(url, data=datas)
                          
                          if min_dist&lt;0.90:
                              frame = cv2.putText(frame, name+' '+ str(min_dist), (int(box[0]),int(box[1])), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,0),1, cv2.LINE_AA)
                          
                          frame = cv2.rectangle(frame, (int(box[0]),int(box[1])) , (int(box[2]),int(box[3])), (255,0,0), 2)
                          
              ret, jpeg = cv2.imencode('.jpg', frame)
              return jpeg.tobytes()
          
      def update(self):
          while True:
              (self.grabbed, self.frame) = self.video.read()
  </code></pre>
  <p>home.html</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;title&gt;Title&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h1&gt;video&lt;/h1&gt;
  
  &lt;table&gt;
      &lt;tr&gt;
          &lt;td width=&quot;50%&quot;&gt;
              &lt;img src=&quot;http://127.0.0.1:8000/detectme&quot; style=&quot;width:400px, height:400px&quot;/&gt;
  
          &lt;/td&gt;
          &lt;td width=&quot;50%&quot;&gt;
              {% block content%}
              &lt;form name=&quot;contents&quot; method=&quot;post&quot; action=&quot;{% url 'page' %}&quot;&gt;
                  
                  &lt;a href=&quot;{% url 'page' %}&quot;&gt;post&lt;/a&gt;
                  &lt;/form&gt;
  
              {{ name }}
              {% endblock %}
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>page.html</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;title&gt;Title&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt; post test &lt;/h1&gt;
  {% block content %}
  {% csrf_token %}
      name : {{ name }} &lt;br&gt;
      pred : {{ pred }}&lt;br&gt;
  {%endblock%}
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>