Error with the for loops in index.html


#1

Everything was working perfectly uptil the admin part,I was able to log in as admin , but when I tried to put that view in the regular template, I was getting the following error:

   OperationalError at /
no such table: collection_smartphone
Request Method:	GET
Request URL:	http://localhost:8000/
Django Version:	1.8.3
Exception Type:	OperationalError
Exception Value:	
no such table: collection_smartphone
Exception Location:	/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py in execute, line 318
Python Executable:	/usr/bin/python
Python Version:	2.7.6
Python Path:	
['/home/vatsal/projects/hellowebapp/hellowebapp',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gst-0.10',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
 Server time:	Fri, 17 Jul 2015 13:57:04 +0000

Error during template rendering

In template /home/vatsal/projects/hellowebapp/hellowebapp/collection/templates/index.html, error at line 4

Invalid block tag: 'endfor', expected 'endblock'
 1	{% extends 'layouts/base.html' %}
 2	{% block title %}Homepage - {{ block.super }}{% endblock %}
 3	{% block content %}
 4		{% for thing in things}
 5		<h2>{{ thing.name }}</h2>
 6		<p>{{ thing.description }}</p>
 7	
  	
       {% endfor %}
  

  
8	
9	{% endblock %}
10	

This is my index.html file:

   {% extends 'layouts/base.html' %}
   {% block title %}Homepage - {{ block.super }}{% endblock %}
   {% block content %}
       {% for thing in things}
       <h2>{{ thing.name }}</h2>
       <p>{{ thing.description }}</p>
       {% endfor %}

   {% endblock %}

Why does it say no such table collection_smartphone? Where should I add it?


#2

No such table means that the database doesn’t exist. You can log into admin even without a database… was the table it’s mentioning showing up in the admin list?


#3

I’m able to see the admin page with the authentication and collection part and when I click on add , I get to the forms and type stuff ,but when I click save, I get the same error. Where and how do I add that table ?


#4

Corrected it by doing

python manage.py syncdb

python manage.py makemigrations 

and then

python manage.py migrate.

So do I have to do this everytime I make a change?


#5

Every time you make a change to models.py, yes (actually should just need to do makemigrations and migrate.) Basically, models.py is a plan to the database… when you change the plan, you need to change the underlying database too to match. :)


#6

Thank you ,got it :D!