我正在尝试在我的django应用程序中实现日历。我跟着这个家伙在另一篇文章中做了什么 here
当我去app / cal时,我得到了所有条目的json响应。我实现fullcalendar的页面我得到500错误。
GET http://127.0.0.1:8000/app/cal/?start=2015-08-30&end=2015-10-11&_=1442333348614 500 (INTERNAL SERVER ERROR)
这是我的代码:
models.py
class Entry(models.Model):
title = models.CharField(max_length=50, blank=True, null=True)
start = models.DateField(blank=True, null=True)
end = models.DateField(blank=True, null=True)
views.py
def eventsFeed(request):
if request.is_ajax():
print 'Its ajax from fullCalendar()'
try:
start = datetime.fromtimestamp(int(request.GET.get('start', False))).replace(tzinfo=utc)
end = datetime.fromtimestamp(int(request.GET.get('end',False)))
except ValueError:
start = datetime.now.replace(tzinfo=utc)
end = start + timedelta(days=7)
entries = Entry.objects.all()
print entries
json_list = []
for entry in entries:
id = entry.id
title = entry.title
start = entry.start.strftime("%Y-%m-%dT%H:%M:%S")
end = entry.end.strftime("%Y-%m-%dT%H:%M:%S")
allDay = False
json_entry = {'id':id, 'title':title, 'start':start, 'end':end, 'allDay':allDay}
json_list.append(json_entry)
return HttpResponse(json.dumps(json_list), content_type='application/json')
urls.py
url(r'^cal/$', eventsFeed, name='cal'),
url(r'^calendar', TemplateView.as_view(template_name='cal/cal.html')),
views.py
def eventsFeed(request):
if request.is_ajax():
print 'Its ajax from fullCalendar()'
try:
start = datetime.fromtimestamp(int(request.GET.get('start', False))).replace(tzinfo=utc)
end = datetime.fromtimestamp(int(request.GET.get('end',False)))
except ValueError:
start = datetime.now.replace(tzinfo=utc)
end = start + timedelta(days=7)
entries = Entry.objects.all()
print entries
json_list = []
for entry in entries:
id = entry.id
title = entry.title
start = entry.start.strftime("%Y-%m-%dT%H:%M:%S")
end = entry.end.strftime("%Y-%m-%dT%H:%M:%S")
allDay = False
json_entry = {'id':id, 'title':title, 'start':start, 'end':end, 'allDay':allDay}
json_list.append(json_entry)
return HttpResponse(json.dumps(json_list), content_type='application/json')
cal.html
<div id="calendar"></div>
<script>
$(document).ready(function(){
$("#calendar").fullCalendar({
events: "/app/cal/"
})
})
</script>
答案 0 :(得分:0)
mysql_database node['mysql_database'] do
connection mysql_connection_info
action [:drop,:create]
end
而非datetime.utcnow().replace(tzinfo=utc)