그래서 두 개의 뷰가 있습니다. 첫 번째 뷰는 요청시 HTML을 생성하고 두 번째 뷰는 첫 번째 뷰를 표시 할 차트를 생성합니다.Django에서 Matplotlib로 동적 차트 생성
HTML보기
def activation_signupcount(request):
if 'datestart' not in request.GET:
return render_to_response('activation/activation_signupcount.html', {'datestart':''})
else:
datestart = request.GET['datestart']
dateend = request.GET['dateend']
return render_to_response('activation/activation_signupcount.html', {'datestart':datestart, 'dateend':dateend})#
차트보기 페이지 activation/activation_signupcount.html
에 따라서
def activation_signupcount_graph(request):
datestart = request.GET['datestart'] #this doesnt work
dateend = request.GET['dateend'] #this doesnt work
print datestart,dateend
# open sql connection
cursor = connection.cursor()
# execute query
cursor.execute("SELECT COUNT(1), JoinDate FROM users WHERE JoinDate BETWEEN '"+ datestart +"' AND '"+ dateend +"' GROUP BY JoinDate;")
# close connection
data = cursor.fetchall()
cursor.close()
connection.close()
fig = Figure()
ax = fig.add_subplot(111)
x = []
y = []
x = [k[1] for k in data]
y = [k[0] for k in data]
ax.plot_date(x, y, '-')
ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d'))
fig.autofmt_xdate()
canvas = FigureCanvas(fig)
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
, 나는 2 개 날짜 필드, 시작하고 GET 요청을 제출 끝을 보유하고 있습니다. 그래서 내 질문은 어떻게 내 함수 activation_signupcount_graph
차트를 생성하는 시작/끝 날짜를 얻으려면이 두 날짜 변수를 구문 분석 할 수 있습니다?
나는 그것이 분명했으면 좋겠다!
아 네 물론! 너무나 분명한 감사! – super9