作成中
django3を使用して、fx通過の変動をグラフにするアプリを作っています
dbはSQLiteです
通貨ごとに関数を分けたいとかんがえたので、
- コンストラクタでdbに通過情報を登録、
- def_GBPNZDでrenderを実行
- 他の通過もdef_〜〜で作成
エラー内容
ですが、下記のエラーがでてしまっています
調べても解決できませんでした
TypeError: def_GBPNZD() missing 1 required positional argument: 'request'
ご教授をおねがいします
ソース
views.py
Python
1from django.shortcuts import render, get_object_or_404, redirect 2from django.http import HttpResponse 3 4import time 5 6import urllib3 7import json 8import sys 9import codecs 10import datetime 11import requests 12from requests import Response 13from apscheduler.schedulers.blocking import BlockingScheduler 14from django.db import models 15import array 16from .models import fxTbl 17 18 19class fx_test(): 20 21 22 times = [] 23 24 25 def __init__(self): 26 27 r = requests.get("https://www.gaitameonline.com/rateaj/getrate") 28 29 fxJson = r.json() 30 31 # 数値がfxのキー 32 # print("[bid]" + data['quotes'][0]['bid'] + " ,[ask]" + data['quotes'][0]['ask']) 33 34 num = 0 35 36 fxtbl = fxTbl() 37 38 while num < 1: 39 40 fxtbl.GBPNZDbid = fxJson['quotes'][0]['bid'] 41 fxtbl.GBPNZDask = fxJson['quotes'][0]['ask'] 42 fxtbl.CADJPYbid = fxJson['quotes'][1]['bid'] 43 fxtbl.CADJPYask = fxJson['quotes'][1]['ask'] 44 fxtbl.GBPAUDbid = fxJson['quotes'][2]['bid'] 45 fxtbl.GBPAUDask = fxJson['quotes'][2]['ask'] 46 47 now = datetime.datetime.now() 48 fxtbl.timestamp = "{0:%Y-%m-%d %H:%M:%S}".format(now) 49 50 fxtbl.save() 51 52 # print(" bid: " + data['quotes'][20]['bid'] + ",\n ask: " + data['quotes'][20]['ask']) 53 54 num += 1 55 56 time.sleep(1) 57 58 59 # def_method 60 61 def def_GBPNZD(self, request): 62 datas = [] 63 64 while fxTbl().GBPNZDbid: 65 add_data = { 66 "bid": fxTbl().GBPNZDbid, 67 "ask": fxTbl().GBPNZDask 68 } 69 datas.append(add_data) 70 71 72 return render( 73 request, 74 'chart/main.html', 75 {'datas': datas} 76 )
models.py
from django.shortcuts import render from django.http import HttpResponse from django.db import models from django.utils import timezone import array # Create your models here. class fxTbl(models.Model): # GBPNZD GBPNZDbid = models.FloatField(verbose_name="GBPNZD_bid", blank=False, null=False) GBPNZDask = models.FloatField(verbose_name="GBPNZD_ask", blank=False, null=False) # CADJPY CADJPYbid = models.FloatField(verbose_name="CADJPY_bid", blank=False, null=False) CADJPYask = models.FloatField(verbose_name="CADJPY_ask", blank=False, null=False) # GBPAUD GBPAUDbid = models.FloatField(verbose_name="GBPAUD_bid", blank=False, null=False) GBPAUDask = models.FloatField(verbose_name="GBPAUD_ask", blank=False, null=False) # timestamp timestamp = models.DateTimeField(default=timezone.now) def __str__(self): return self
urls.py
from django.urls import path from borderChart import views urlpatterns = [ path('', views.fx_test.def_GBPNZD), path('GBPNZD', views.fx_test.def_GBPNZD) ]
main.html
{% load static %} <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>3秒</title> <link rel="stylesheet" href="{% static 'chart/css/style.css' %}"> </head> <body> <p>BID:売値、ASK:買値</p> <p>USDJPY<p> <div id="myDiv"></div> <script src="https://cdn.plot.ly/plotly-latest.min.js"></script> <script> var bid_data = { x: [ {% for data_bid in bid %} {{ forloop.counter }}, {% endfor %} ], y: [ {% for data_bid in bid %} {{ data_bid }}, {% endfor %} ], type: 'scatter', name: 'ask' }; var ask_data = { x: [ {% for data_ask in ask %} {{ forloop.counter }}, {% endfor %} ], y: [ {% for data_ask in ask %} {{ data_ask }}, {% endfor %} ], type: 'scatter', name: 'bid' }; var datas = [bid_data, ask_data]; Plotly.newPlot('myDiv', datas); </script> <script src="{% static 'chart/js/index.js' %}"></script> {{ bid }}:bid<br> {{ ask }}:ask,<br> </body> </html>
回答1件
あなたの回答
tips
プレビュー