Как запустить внешний файл python и показать данные во фронт-энде django в виде таблицы

Привет ребята я хочу запустить свой внешний py scipt и вывод будет на json я хочу показать данные в виде строк и таблицы в front end, данные динамического регрессионного тестирования. как мне показать это используя django

Здесь я попытался дать ответ, как я понимаю ваш вопрос.

фиктивные JSON данные (вы можете взять JSON данные, которые получили из файла)

    json_response_from_file= [
      {
      "title": "HP Pavilion 15-DK1056WM",
      "price": 1099,
      "brand": "HP Pavilion",
      "category": "laptops",
      "thumbnail": "https://i.dummyjson.com/data/products/10/thumbnail.jpeg",
      "images": [
        "https://i.dummyjson.com/data/products/10/1.jpg",
        "https://i.dummyjson.com/data/products/10/2.jpg",
        "https://i.dummyjson.com/data/products/10/3.jpg",
        "https://i.dummyjson.com/data/products/10/thumbnail.jpeg"
      },
      {
      "title": "Redmi I-10",
      "price": 1100,
      "brand": "Redmi",
      "category": "mobile",
      "thumbnail": "https://i.dummyjson.com/data/products/10/thumbnail.jpeg",
      "images": [
        "https://i.dummyjson.com/data/products/10/1.jpg",
        "https://i.dummyjson.com/data/products/10/2.jpg",
        "https://i.dummyjson.com/data/products/10/3.jpg",
        "https://i.dummyjson.com/data/products/10/thumbnail.jpeg"
      },
    
      ]

Django views.py

import json
def Oneview(request):
    data=file_json_response
    context = {'data':json.loads(json_response_from_file)}
    return render(request,'index.html',context)

HTML код

    <!doctype html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Bootstrap demo</title>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"  >
      </head>
      <body>
        
        <table class="table">
            <thead>
              <tr>
                <th scope="col">No.</th>
                <th scope="col">Thumbnail</th>
                <th scope="col">Name</th>
                <th scope="col">Price</th>
                <th scope="col">Brand</th>
                <th scope="col">Category</th>
                <th scope="col">All-Images</th>
              </tr>
            </thead>
            <tbody>
                
                {% for i in data %}
                <tr>
                    <th >{{forloop.counter}}</th>
                    <td>{{i.thumbnail}}</td>
                    <td>{{i.title}}</td>
                    <td>{{i.price}}</td>
                    <td>{{i.brand}}</td>
                    <td>{{i.category}}</td>
                    <td>
                        {% for j in i.images %}
                            <div>{{j}}</div>
                        {% endfor %}
                    </td>
                </tr>
                {% endfor %}
            </tbody>
          </table>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"  ></script>
      </body>
    </html>
Вернуться на верх