I'm following a course in Python and Django, and the problem starts when the course version is 1.1.2 and mine is 1.8.2
I was able to generate a form to save "Events", but when I click submit, it returns the following error:
OperationalError at /adiciona/
no such table: agenda_itemagenda
Request Method: POST
Request URL: http://127.0.0.1:8000/adiciona/
Django Version: 1.8.2
Exception Type: OperationalError
Exception Value:
no such table: agenda_itemagenda
Exception Location: C:\wamp\www\curso python\aula\aula\lib\site-packages\django-1.8.2-py2.7.egg\django\db\backends\sqlite3\base.py in execute, line 318
Python Executable: C:\wamp\www\curso python\aula\aula\Scripts\python.exe
Python Version: 2.7.9
Python Path:
['C:\wamp\www\curso python\aula\aula\gerenciador',
'C:\wamp\www\curso python\aula\aula\lib\site-packages\django-1.8.2-py2.7.egg',
'C:\WINDOWS\SYSTEM32\python27.zip',
'C:\wamp\www\curso python\aula\aula\DLLs',
'C:\wamp\www\curso python\aula\aula\lib',
'C:\wamp\www\curso python\aula\aula\lib\plat-win',
'C:\wamp\www\curso python\aula\aula\lib\lib-tk',
'C:\wamp\www\curso python\aula\aula\Scripts',
'C:\Python27\Lib',
'C:\Python27\DLLs',
'C:\Python27\Lib\lib-tk',
'C:\wamp\www\curso python\aula\aula',
'C:\wamp\www\curso python\aula\aula\lib\site-packages']
Server time: Fri, 5 Jun 2015 01:10:35 -0300
agenda.py
from django.db import models
class ItemAgenda(models.Model):
titulo = models.CharField(max_length=100)
data = models.DateField()
hora = models.TimeField()
descricao = models.TextField()'
views.py
#-*- encoding: utf-8 -*-
from django.shortcuts import render_to_response
from django.template import RequestContext
# Create your views here.
from models import ItemAgenda
from forms import FormItemAgenda
def lista(request):
lista_itens = ItemAgenda.objects.all()
return render_to_response("lista.html", {'lista_itens': lista_itens})
def adiciona(request):
if request.method == "POST":
form = FormItemAgenda(request.POST, request.FILES)
if form.is_valid():
dados = form.cleaned_data
item = ItemAgenda(
titulo=dados['titulo'],
data=dados['data'],
hora=dados['hora'],
descricao=dados['descricao']
)
item.save()
return render_to_response("salvo.html", {})
else:
form = FormItemAgenda()
return render_to_response("adiciona.html", {'form': form},
context_instance=RequestContext(request))
forms.py
from django import forms
class FormItemAgenda(forms.Form):
titulo = forms.CharField(max_length=100)
data = forms.DateField(
widget=forms.DateInput(format='%d/%m/%Y'),
input_formats=['%d/%m/%Y', '%d/%m/%y'])
hora = forms.TimeField()
descricao = forms.CharField()
# Create your models here.
list.html
{% extends 'base.html' %}
{% block corpo %}
<a href="/adiciona/"> Adicionar novo item </a>
<ul>
{% for item in lista_item %}
<li>
<a href="/item/{{ item.id }}">
{{ item.data|date:'d/m/Y'}} - {{ item.titulo }}
</a>
</li>
{% empty %}
<li> Sem itens na lista</li>
{% endfor %}
</ul>
{% endblock %}
add.html
{% extends "base.html" %}
{% block corpo %}
<form action="" method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Adicionar</button>
</form>
{% endblock %}