Django

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() 


Simple_tag and inclusion_tag

1. Создаем модуль templatetags

2. Создаем файл learn_tag

from django import template

register = template.Library()

@register.simple_tag(name='get_list')

def get_list():

    return ['One', 'two', 'three', 'four', 'five']

3. В html {% load learn_tag %}

{% load learn_tag %}

<!DOCTYPE html>

<html lang="en">

<head> 

    <meta charset="UTF-8">

    <title>Title</title>

</head>

<body>

{% get_dict %}

{% get_list as list %}

{% for item in list %}

    {{ item|capfirst }}

    <br>

{% endfor %}

</body>

</html>

4.About.html

<h1>{{ title }}</h1>

<p>{{ content }}</p>

Как установить buildozer для kivy

sudo apt update sudo apt install python3 python3-pip pip3 install --user --upgrade buildozer sudo apt install -y git zip unzip openjdk-17-jd...