Im working with django, building a web app. I have most stuff working. The general structure is I have a user tied to a list of elements. When I click on those elements, I get a 404 page not found error.
Heres some of models.py:
class Event(models.Model):
#user that created the event
#event title
title = models.CharField(max_length=200)
#time created
created = models.DateField('Date Created',auto_now_add=True)
#description of event from user
description = models.CharField(max_length=400)
#address of event if existant
address = models.CharField(max_length=50)
class User(models.Model):
attending = models.ManyToManyField('Event', related_name='User_attending')
hosting = models.ForeignKey('Event', related_name='User_hosting')
gender = models.IntegerField(max_length=1)
password = models.CharField(max_length=100)
email = models.CharField(max_length=100)
age = models.IntegerField()
fName = models.CharField(max_length=25)
lName = models.CharField(max_length=25)
id = models.AutoField(primary_key=True)
From views.py, when I try and access the html page attached to my "event" object, I get a 404 error because my code doesnt recognize "Event".
from list.models import *
def event(request, id):
#e = Event()
#code.interact(local = locals())
try:
e = Event.objects.get(User_hosting=id)
except Event.DoesNotExist:
raise Http404
if e.user_id != request.user.id:
raise Http404
#code.interact(local = locals())
return render_to_response('event/event.html', {'event':e})
When I use the shell, e = Event.objects.get(User_hosting=id) it says that "Event is not defined".
You have to import any modules or classes you want to use in the shell. Try this (where
appnameis the name of your app.