I want to pass two parameters to the end-point of my Django API. This is the first Django API that I am doing. Currently I hardcoded the input parameters in data = {'param1':[0.4],'param2':[0.9]}
.
Then I want to be able to call this end-point as follows http://localhost:8000&lat=50¶m2=30
How should I update this code of view.py
in order to obtained the desired functionality?
from django.http import HttpResponse
import pandas as pd
import json
# used to export a trained model
from sklearn.externals import joblib
def index(request):
decision_tree = joblib.load('proj/model/decision_tree.pkl')
# now I manually pass data, but I want to get it from request
data = {'param1':[0.4],'param2':[0.9]}
test_X = pd.DataFrame(data)
y_pred = decision_tree.predict(test_X)
response_data = {}
response_data['prediction'] = y_pred
response_json = json.dumps(response_data)
return HttpResponse(response_json)