0

I am using Django with Neo4j as DB (nep4django).

I have a primitive template to display the list of 3 cities, like I do it with Django python shell:

In [8]: from mydb.models import Place

In [9]: cities = Place.objects.all()

In [10]: for city in cities:
   ....:     print city.name
   ....:     
Paris
Zurich
London

my template cities.html:

<!DOCTYPE html>
<html><head><title>Cities</title></head>
    <body>
        <h1>Cities</h1>
        <ul>
            {% for city in cities %}
            <li>{{ city.name }}</li>
            {% endfor %}
        </ul>
    </body></html>

On my http://localhost:8000/cities/ page I don't get any error, but the only thing that is displayed is Cities. So, I have title and h1 displayed, but not the ul part, where I actually use my DB. How can I fix this?

views.py file:

from django.shortcuts import render_to_response
from models import Place

def show_places(request):
   cities = Place.objects.all()
   return render_to_response('cities.html', {'List of cities': cities})

urls.py file:

from django.conf.urls import patterns, include, url
from neo4django import admin
from mydb.views import show_places

admin.autodiscover()

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    (r'^cities/', show_places),
)
user3241376
  • 407
  • 7
  • 20

1 Answers1

1

Change List of cities by cities. You are asigning that variable name.

dhana
  • 6,487
  • 4
  • 40
  • 63
cor
  • 3,323
  • 25
  • 46
  • 1
    Sometimes we are looking for complicated solutions, and the problem is not that far. Thanks for the edition, now the answer is looking better. You have good tools to be greatful ;) – cor May 06 '14 at 11:05
  • Just wanted to say thanks because your answer fixed my bug (I forgot the quotes in the context dictionary). Totally unrelated but thanks :) – Alex Weavers Jan 05 '19 at 11:04