How do I display variables on a django page?

0

I am new to django and am taking some information from a web page using lxml. I would like to know how I can display the values on my web page.

import requests
from lxml import html
from django.shortcuts import render


def list_data(request):  
    return render(request, 'data.html', {})


def get_idhm(url):
    page = requests.get(url)
    tree = html.fromstring(page.content)
    idhm = tree.xpath('//*[@id="responseMunicipios"]/ul/li[6]/div/p[2]/text()')
    return idhm[0]


def get_population(url):
    page = requests.get(url)
    tree = html.fromstring(page.content)
    values = tree.xpath('//*[@id="responseMunicipios"]/ul/li[3]/div/p[2]/text()')
    return values[0]

this is the view.

    
asked by anonymous 18.04.2018 / 23:09

1 answer

0

As you can see in the example you have shown, there is a method called list_data . In it you render data.html and an empty dictionary. In this dictionary you can enter the values that will be displayed in the HTML. Here's an example:

views.py

def list_data(request):  
    return render(request, 'data.html', {"message": "Hello World"})

data.html

<p>{{message}}</p>
    
18.04.2018 / 23:49