Django с PostgreSQL в Astra Linux SE 1.5

Устанавливаем необходимые пакеты с зависимостями: postgresql, python-psycopg2. В ALSE 1.5 основная версия PostgreSQL 9.4.5. Редактируем конфигурационный файл базы данных $ sudo vim /etc/postgresql/9.4/main/pg_hba.conf Комментируем или удаляем все строки и дописываем новые, разделяя поля табуляцией local all postgres trust local all all trust host all all 127.0.0.1/32 trust host all all 192.168.15.129/24 trust host all all 192.168.15.132/24 trust Последние строки - адреса сервера и клиента, которым будем подключаться. Меняйте на свои или укажите всю сеть, например 192.168.15.0/24. ...

<span title='2022-02-19 00:00:00 +0000 UTC'>February 19, 2022</span>

Web-приложение на Python в Astra Linux с ALD авторизацией

Как настроить сервер - контроллер домена ALD и подключиться к нему клиентом в статье Настройка входа в систему с Astra Linux Directory. Устанавливаем web-сервер (если еще не установлен), нужные нам модули apache и пакет с django $ sudo apt-get install apache2 libapache2-mod-auth-kerb libapache2-mod-python python-django Включаем модули apache, с которыми будем работать, отключаем лишний auth_pam, если ранее с ним работали, затем запускаем web-сервер $ sudo a2dismod auth_pam $ sudo a2enmod python $ sudo a2enmod auth_kerb $ sudo service apache2 reload Создаем принципала в ALD и добавляем его в группу mac ...

<span title='2022-02-18 00:00:00 +0000 UTC'>February 18, 2022</span>

Запуск Django-приложений через mod_python в Astra Linux SE 1.5

Считаем, что Apache уже установлен и настроена аутентификация и авторизация через PAM (см. Настройка web-сервера на Astra Linux SE 1.5) Устанавливаем необходимые пакеты: # apt-get install libapache2-mod-python python-django Включаем модуль: # a2enmod python Создаем проект Django и каталог для log-файлов: # cd /var/www # django-admin startproject django_site # mkdir django_site/log В /etc/apache2/sites-available/ создаем файл django_site. Это файл конфигурации виртуального хоста для нашего Django-проекта, лежащего в каталоге /var/www/django_site/. <VirtualHost *:80> ServerAdmin webmaster@domain.name ServerName server.domain.name DocumentRoot /var/www/django_site <Directory "/var/www/django_site/"> AuthPAM_Enabled on AuthType Basic AuthName "PAM authentication" require valid-user Options -Indexes FollowSymLinks -MultiViews AllowOverride None Order deny,allow Allow from all </Directory> <Location "/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE django_site.settings PythonOption diango.root /var/www/django_site PythonPath "['/var/www/django_site/',] + sys.path" PythonAutoReload On </Location> <Location "/media/”> SetHandler None </Location> <Location "/static/"> SetHandler None </Location> <LocationMatch "\.(jpg|gif|png)$"> SetHandler None </LocationMatch> ErrorLog /var/www/django_site/log/error.log LogLevel warn CustomLog /var/www/django_site/log/access.log combined </VirtualHost> Включаем наш сайт в список разрешенных и перезапускаем web-сервер ...

<span title='2022-02-04 00:00:00 +0000 UTC'>February 4, 2022</span>

Starting a production Django server

I wrote ansible playbook for starting up a production Django server with PostgreSQL, Gunicorn and Nginx. When I tested the script, I used the Ubuntu Server image from this link. All I needed to install additionally was an ssh server for ansible to work. sudo apt update && sudo apt upgrade sudo apt install openssh-server I used a VirtualBox image and set the network settings to bridge mode. The IP address was obtained via the dhcp protocol. The command to display the ip address is ip addr. ...

<span title='2021-10-15 00:00:00 +0000 UTC'>October 15, 2021</span>

Deploying the django app on the DigitalOcean App Platform

For deploying Django apps, I tried PaaS such as Heroku and Pythonanywhere. It’s the turn of the DigitalOcean App Platform. And so far, this is the easiest and fastest way to deploy a Django app in production. There is awesome guide on how to do this on DigitalOcean’s tutorials. For testing, I wrote a small application that generates a configuration snippet for configuring ssh on cisco devices. For simplicity, I didn’t use a database and static content. For such an application, in fact, there is no need for a server side, just JavaScript is enough :) ...

<span title='2021-07-21 00:00:00 +0000 UTC'>July 21, 2021</span>

Creating dockerized Django app with VSCode

Thanks to Mark Winterbottom for the interesting videos and the idea for this post. Creating a Django project Start by creating a new directory for your project (eg: vscode-django-docker), and open it in VSCode. mkdir vscode-django-docker cd vscode-django-docker git init code . Then, add a .gitignore for your project. You can use template for Python provided by GitHub or generate on gitignore.io. Now let’s create a Django project by running the one-line-command below ...

<span title='2021-06-12 00:00:00 +0000 UTC'>June 12, 2021</span>

Django project deployed on Heroku

About a year ago, I published a web-based task management application written with Flask. It looked like this: Since a year has passed, I decided to rewrite this project in Django, and also try to deploy it to PaaS Heroku. I’ve also made some improvements, including design, authorization, database management, and web security issues. That’s what happened: Links: Try it in live on Heroku GitHub repository

<span title='2021-03-25 00:00:00 +0000 UTC'>March 25, 2021</span>

Django REST API with React App step-by-step

I use PyCharm for python projects and pipenv for package management. Start new PyCharm project named django-rest-react-blog Optionally git init clone gist .gitignore for Django and React projects Main course pipenv install django pipenv install djangorestframework pipenv install ipython --dev django-admin.py startproject bookcase cd bookcase python manage.py startapp mainapp Edit bookcase/settings.py: ... INSTALLED_APPS = [ ... 'rest_framework' ] ... TEMPLATES = [ { ... 'DIRS': [BASE_DIR / 'mainapp-ui/build'], ... }, ] ... STATIC_ROOT = BASE_DIR / 'static' STATICFILES_DIRS = ( (BASE_DIR / 'mainapp-ui/build/static'), ) Edit mainapp/views.py: from django.shortcuts import render def index(request): return render(request, 'index.html', {}) Edit bookcase/urls.py: ... from mainapp.views import index urlpatterns = [ ... path('', index) ] make dir mainapp/api with files there: ...

<span title='2021-02-27 00:00:00 +0000 UTC'>February 27, 2021</span>

Facial recognition with Python

I tried the facial recognition library for Python ageitgey/face_recognition. This library uses dlib, a toolkit written in C++ that contains machine learning algorithms. For example, I’m trying to check if an actor is playing in the TV series “The Big Bang Theory”. A test image with an actor is compared to real actors filmed in a TV show. I wrote a web service that uses python face_recognition library for face recognition from image and compares the recognized face with the data stored in the database. ...

<span title='2021-01-18 00:00:00 +0000 UTC'>January 18, 2021</span>