[Python] Show the text from a Json file in Django template

Discussão em 'Python' iniciado por Stack, Agosto 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am starting learn django,I have made some basic templates/views and want to show the text from a json file located in the assets/jsons folder.The file is called "quotes.json" The content of the json file:

    {
    "emp_details": [
    {
    "emp_name": "johnny",
    "email": "example1.mail@gmail.com",
    "job_profile": "intern"
    },
    {
    "emp_name": "gustav",
    "email": "gustav.empl@gmail.com",
    "job_profile": "developer"
    },
    {
    "emp_name": "emily",
    "email": "emily@gmail.com",
    "job_profile": "Full Time"
    }
    ]
    }


    here is the views.py:

    from django.http import HttpResponse
    from django.shortcuts import render


    from django.contrib.auth import get_user_model


    #from . import models

    def homepage(request):
    ##here is where I want to have the json data
    ##and return it in the render along with the request and 'homepage.html'

    return render(request,'homepage.html')

    def about(request):
    return render(request,'about.html')

    def users(request):

    User = get_user_model()
    users = User.objects.all()


    return render(request,'users.html',{'users':users})




    here is the homepage.html ,the layout.html has css and some navigation buttons it is irrelevant. I literally only want the contents of the json to be shown as text in the homepage.

    {% extends 'layout.html' %}




    {% block title %}
    Home
    {% endblock %}


    {% block content %}


    {% load static %}







    {% load static %}
    <script type="text/javascript">

    console.log(json1_data);
    </script>


    <h1>Home</h1>

    <h1><p>Welcome {{request.user}}</p></h1>





    <p>Check out my <a href="/about">About</a> page.</p>


    <p id="demo"> </p>






    {% endblock %}



    I tried importing the file with basic python but did nor really have much success

    Continue reading...

Compartilhe esta Página