TypeError at /accounts/result float() argument must be a string or a numberとエラーが出ました。
views.pyに
@login_required def result(request): return render(request, 'result.html', {'chart': _view_plot(request)}) def _view_plot(request): results = ImageAndUser.objects.filter(user=request.user).order_by('-date') left = np.array([results[0], results[1],results[2], results[3], results[4]]) height = np.array([100, 300, 200, 500, 400]) plt.plot(left, height) plt.xticks(left, ['2016-04-10', '2016-10-05', '2016-10-10', '2016-10-11', '2016-12-10']) jpg_image_buffer = cStringIO.StringIO() plt.savefig(jpg_image_buffer) array = base64.b64encode(jpg_image_buffer.getvalue()) jpg_image_buffer.close() return array
と書きresultメソッドを呼び出した時このようなエラーが出ました。Tracebackには
Traceback: File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner 39. response = get_response(request) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response 187. response = self.process_exception_by_middleware(e, request) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/handlers/base.py" in _get_response 185. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view 23. return view_func(request, *args, **kwargs) File "/Users/xxx/Downloads/App/accounts/views.py" in past_result 342. return render(request, 'registration/past_result/result.html', {'chart': _view_plot(request)}) File "/Users/xxx/Downloads/App/accounts/views.py" in _view_plot 348. plt.plot(left, height) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.py" in plot 2987. ret = ax.plot(*args, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py" in plot 4138. self.add_line(line) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py" in add_line 1497. self._update_line_limits(line) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py" in _update_line_limits 1508. path = line.get_path() File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/lines.py" in get_path 743. self.recache() File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/lines.py" in recache 420. x = np.asarray(xconv, np.float_) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/numeric.py" in asarray 531. return array(a, dtype, copy=False, order=order) Exception Type: TypeError at /accounts/past_result Exception Value: float() argument must be a string or a number
と出ていました。floatを指定した所はどこにもなくてなぜこのようなエラーが出てしまうのかわかりません。
どのようにエラーを直せば良いのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。