Hey folks, I am new on the forum and new to Python.
I am making a news site and using python/django. My site will get all the news from the DB and fill up the template. As there is about 10 lines for the news and at some moment i may not have 10 news i want to test if that exists before send it to render, how can I do that?
Down is my code:
def teste(response):
cursor = connection.cursor()
cursor.execute("SELECT n.titulo_principal,n.desc_resumida FROM
polls_ordem_noticias o inner join polls_noticias n on
n.id_serial=o.id_noticia order by posicao")
n=cursor.fetchall()
t=get_template('Inicial.html')
c= Context({
'Titulo_Noticia_1':n[0][0],'Descricao_Noticia_1':n[0][1],'Link_Noticia_1':n[0][0],
'Titulo_Noticia_2':n[1][0],'Descricao_Noticia_2':n[1][1],'Link_Noticia_2':n[1][0]
})
return HttpResponse(t.render(c))