How can I pass a list of items into a template?
In my views:
from django.shortcuts import render, render_to_response
from django.http import HttpResponse
from django.template import loader
from django.views.decorators.csrf import csrf_exempt
from .models import Question
from .forms import usersData1, usersData2, usersData3
def start_pr(response):
name = ["Name","Phone Number","Email"]
form = usersData1()
return render_to_response(response, "start_pr/start.html", {"form":form}, {"name":name})
In my HTML:
{% block content %}
<form action="/start/" method="post">
<legend>
{%for items in form %}
{% for obj in name %}
<p> {{ obj }} </p>
{% endfor %}
<input type="text" name="name" maxlength="20" required="" id="id_name" placeholder="{{items.name}}">
<br>
{% endfor %}
<a href="#">next</a>
</legend>
</form>
{% endblock %}
In my forms:
from Django import forms
class usersData1(forms.Form):
name= forms.CharField(label="name", max_length=20)
phoneNum= forms.IntegerField(label="phoneNum")
email= forms.EmailField(label="email", max_length=50)
The list is in my views as name. I have used {% for obj in name %}<p>{{obj}}</p>.
When I go to localhost:8000 it shows an HTML form as the out product. which is weird (like opening up google view page sources when right-clicked). I am also new to Django but know how to make views and link them along with most of the basics.
What I don't know is this {%%}; what is this symbol called, and where can I find documentation on this syntax?
What I am trying to achieve in this Django view is to have 3 boxes with names from the list name as the name for that box (pretty much an iteration).