This repository has been archived on 2024-01-13. You can view files and clone it, but cannot push or open issues or pull requests.
arka-mvp/api/views.py

32 lines
965 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json
import traceback
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseBadRequest
from .api_methods import api_call_method, api_get_documentation
from .api_errors import *
def view_methods(request):
methods = api_get_documentation()
return render(request, 'api/index.html', {'api_methods': methods})
def call_method(request, method_name):
if request.method == "GET":
params = request.GET
elif request.method == "POST":
params = request.POST
else:
return HttpResponseBadRequest()
api_params = {}
for p in params:
# защита от нескольких параметров с одним именем
api_params[p] = params[p]
out = api_call_method(method_name, api_params)
response = HttpResponse(json.dumps(out, ensure_ascii=False, indent=4))
response.headers["Content-type"] = "application/json; charset=utf-8"
return response