Django projects for Android

The following represents the fundamental structure of a Django project, illustrating its essential components and organization.
For a practical illustration, here’s an example: Django Application Example on GitHub.
[ ]:
django_app/
    .p4a                    # Configuration files for Python-for-Android
    blacklist.txt           # List of items to exclude from the build
    whitelist.txt           # List of items to include in the build
    django_app/
        main.py             # Main entry point for the Django application
        test_project/       # Test project directory
-->     radiant/            # Radiant framework module, more details at: [Radiant Framework GitHub](https://github.com/dunderlab/python-radiant_framework/tree/main/radiant)
-->     django/             # Django source, see: [Django GitHub Repository](https://github.com/django/django/tree/main/django)
        test_project/       # Main Django project directory
            manage.py       # Django's command-line utility for administrative tasks
            test_project/   # Inner Django project directory
                __init__.py # Indicates a Python package
                asgi.py     # ASGI config for Django project
                settings.py # Settings/configuration for Django project
                urls.py     # URL declarations for Django project
                wsgi.py     # WSGI config for Django project

In the Django app’s structure, special attention must be given to the radiant/ and django/ directories. It’s crucial to include the source code of these modules, as the python-for-android tool compiles source files into .pyo format. Pre-compiled modules or packages typically installed via package managers are not suitable for this process. This approach ensures that the python-for-android compiler effectively processes the source code of the Radiant Framework and Django, making them functional within the compiled Android application.

For additional configuration options and detailed instructions on building Android applications with Python, refer to the Python for Android Documentation.

[ ]:
# .p4a

--no-byte-compile-python
--private django_app
--package org.example.django_app
--name "My WebView Django Application"
--dist_name django_app
--version 0.1
--bootstrap webview
--requirements python3,hostpython3,sqlite3,sqlparse,asgiref,pytz,pyjnius
--whitelist whitelist.txt
--port 5000

The path to a file containing blacklisted patterns that will be excluded from the final AAR.

[ ]:
# blacklist.txt

*.pyc

The path to a file containing whitelisted patterns that will be included in the AAR even if also blacklisted.

[ ]:
# whitelist.txt

sqlite3/*
lib-dynload/_sqlite3.so
*.py

{{use radiant.compiler.server to sevr the application}}

[ ]:
# main.py

import sys
import os
from radiant.compiler import server

sys.path.append(os.path.join(os.path.dirname(__file__), "test_project"))
server.main(ip='localhost', port=5000)

To compile the project and generate the corresponding SDK file, follow the established build procedures outlined in the documentation. This process ensures that all necessary components are correctly assembled and the SDK file is prepared for deployment.

[ ]:
$ radiant_p4a apk --arch arm64-v8a