from django.http import HttpResponse
import urllib.request
import pymysql
def hello(req):
if req.method == "GET":
json_str = req.GET.get("test")
else:
json_str = req.POST.get("test")
resp = urllib.request.urlopen(json_str)
buff = resp.read()
view = buff.decode("utf8")
conn = pymysql.connect('localhost', 'root', '123456', 'test', charset='utf8')
cursor = conn.cursor()
sql = "INSERT INTO role (rname) VALUES (%(rname)s)"
value = {"rname" : view}
cursor.execute(sql, value)
conn.commit()
resp.close()
"""
sse = "Select * from role"
cursor.execute(sse)
data = cursor.fetchall();
print(data)
"""
return HttpResponse("hello world")