ALLOWED_HOSTS = ['192.168.0.106','192.168.0.107', '192.168.0.105'] разрешенные хосты
CORS_ALLOWED_ORIGINS = [ "http://192.168.0.106", ]
CSRF_TRUSTED_ORIGINS = [ "http://192.168.0.106", ]
from django.views.decorators.csrf
import csrf_exempt path('apartment', csrf_exempt(views.apartment)), исключение проверки csrf
Обработка данных JSON POST запрос:
get_data=request.body.decode('utf-8')
get_body=json.loads(get_data)
Вернуть ответ в виде JSON:
return HttpResponse(json.dumps(mae), content_type='application/json')
python -m pip install mysqlclient==1.4.2.post1
Функция выборки MYSQL:
def getData(self):
with connection.cursor() as cursor:
cursor.execute( "SELECT id, rooms, floor, etajnost, price, date, location, area, favorites FROM olx_apartments")
return cursor.fetchall()
Функция обновить MYSQL:
def setNewPrice(self, data):
count = data.id.count() for i in range(0, count):
with connection.cursor() as cursor:
sql = f"UPDATE olx_apartments SET real_price = {int(data['Predict'][i])} WHERE id = {data['id'][i]}"
cursor.execute(sql)
connection.commit()