Содержание файла JSON:
Код: Выделить всё
{
"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"
}
]
}
< /code>
Вот 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})
< /code>
Вот Homepage.html, макет. Html имеет CSS и некоторые навигационные кнопки. Я буквально хочу, чтобы содержимое JSON было показано в виде текста на домашней странице. < /P>
{% extends 'layout.html' %}
{% block title %}
Home
{% endblock %}
{% block content %}
{% load static %}
{% load static %}
console.log(json1_data);
Home
Welcome {{request.user}}
Check out my [url=/about]About[/url] page.
{% endblock %}
Подробнее здесь: https://stackoverflow.com/questions/797 ... o-template