Error in html django?

2

Good morning, I have a small problem to reference my variable in django html. I'm a beginner on the web part, I'm trying to create a website for a project, then during the construction of the html, I tried to make a reference for my view.py, but it does not find the text saved in the "texts" variable.

Additional information

1) I'm working with Sublime Text 3. (If it makes any difference)

2) I have already added the plugins: Django, anaconda (configured), Css3, html5 and ement.

Could you help me to understand this problem?

Follow html code:

   </div>
    <div class="container">
		<div class="jumbotron page-header">
		  <h1>{{ title|capfirst }}</h1>
		  <p> 
		  	  {% for item in texts %}
		  	  {{item}},
		  	  {% endfor %}
		  	   
		  </p>

View.py from django:

# coding=utf-8

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


def index(request):
     texts = ['Lorem ipsum dolor sit amet, consectetur adipisicing 
     elit, sed do eiusmod tempor incididunt ut labore et dolore magna 
     aliqua']
context = {
    'title':'django e-commerce',
    'texts':texts
}
     return render(request, 'index.html', context)
    
asked by anonymous 18.08.2017 / 15:53

1 answer

1

I do not know if there was any error in control-c / control-v, but the way your code should not even compile, your texts are breaking line without the scape for that. Also, it makes no sense to just place a string in the txts list and then access it through for . Try following the steps below and see if it works:

views.py:

from django.shortcuts import render
def index(request):
    texts = ['Primeira String', 'Segunda string', 'Terceira String']
    context = { 'title':'django e-commerce', 'texts':texts }

    return render(request, 'core/index.html', context)

index.html

{% for t in texts %}
    <p>{{ t }}</p>
{% endfor %}

When you run it should appear in the browse:

    
18.08.2017 / 22:56