python - Dictionary is not accessed in template page in django -
i new django. trying pass 1 dictionary template view page when try print dictionary value using loop not print.
-mytest -personal -templates -personal -includes -basic.html -header.html -home.html -urls.py -views.py -webapp
view.py
from django.shortcuts import render # create views here. def index(request): return render(request,'personal/home.html') def contact(request): return render(request,'personal/basic.html',{'contents':['if contact me, please email me','ansarijuned@gmail.com']})
basic.html
{% extends "personal/header.html" %} {% block content %} <p>this home page header</p> <div class="container"> <div class="row"> <div class="col-lg-12"> <h2>contact us</h2> <hr /> <% obj in contents %> <p>{{ obj }}</p> <% endfor %> </div> </div> </div> {% include "personal/includes/headerwidget.html" %} {% endblock %}
urls.py
from django.conf.urls import url, include . import views urlpatterns = [ url(r'^$', views.index, name='index'), url(r'^contact/', views.contact, name='contact'), ]
in template trying access {{c}}
object not exist. data in {{obj}}
, can access way :
{% obj in contents %} {{ obj }} {% endfor %}
then if want test whether obj
equal hi
can :
{% obj in contents %} {% if obj == "hi" %} {{ obj }} {% endif %} {% endfor %}
Comments
Post a Comment