0
def details(request, id):
event = Event.objects.filter(id=id)
return render(request, 'details.html', {'Event' : event})
模板:
{% if Event %}
<h1>Event Name: {{ Event.name }}</h1>
{% else %}
No Event.
{% endif %}
型號:
class Event(models.Model):
name = models.CharField(max_length = 30)
artist = models.ManyToManyField(Artist)
venue = models.ForeignKey(Venue)
event_date = models.DateTimeField('event date')
on_sale = models.DateTimeField('on sale time')
def __unicode__(self):
return unicode(self.name)
當我打開它只是加載Event Name:
的頁面。當我刪除.name
屬性時,它會在事件輸入數據庫時加載該事件,但不會加載該對象的任何屬性。感謝任何幫助/建議,謝謝。