{"id":31859498,"url":"https://github.com/python-ellar/ellar-django-module","last_synced_at":"2025-10-12T15:26:04.060Z","repository":{"id":173910821,"uuid":"651041882","full_name":"python-ellar/ellar-django-module","owner":"python-ellar","description":"Integrates Django ORM with Ellar","archived":false,"fork":false,"pushed_at":"2025-02-01T16:50:18.000Z","size":168,"stargazers_count":2,"open_issues_count":5,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-29T14:58:45.819Z","etag":null,"topics":["django","django-orm","ellar","ellar-django","fastapi-django"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/python-ellar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-08T11:11:31.000Z","updated_at":"2024-11-20T05:41:13.000Z","dependencies_parsed_at":"2023-09-01T09:22:47.994Z","dependency_job_id":"f0fe7f43-1faa-4add-8f51-f00a14188e1b","html_url":"https://github.com/python-ellar/ellar-django-module","commit_stats":null,"previous_names":["eadwincode/ellar-django-module","python-ellar/ellar-django-module"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/python-ellar/ellar-django-module","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-ellar%2Fellar-django-module","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-ellar%2Fellar-django-module/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-ellar%2Fellar-django-module/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-ellar%2Fellar-django-module/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/python-ellar","download_url":"https://codeload.github.com/python-ellar/ellar-django-module/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-ellar%2Fellar-django-module/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279011850,"owners_count":26085004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-orm","ellar","ellar-django","fastapi-django"],"created_at":"2025-10-12T15:26:01.057Z","updated_at":"2025-10-12T15:26:04.045Z","avatar_url":"https://github.com/python-ellar.png","language":"Python","readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"#\" target=\"blank\"\u003e\u003cimg src=\"https://python-ellar.github.io/ellar/img/EllarLogoB.png\" width=\"200\" alt=\"Ellar Logo\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003eEllar - Python ASGI web framework for building fast, efficient, and scalable RESTful APIs and server-side applications.\u003c/p\u003e\n\n![Test](https://github.com/python-ellar/ellar-django-module/actions/workflows/test_full.yml/badge.svg)\n![Coverage](https://img.shields.io/codecov/c/github/python-ellar/ellar-django-module)\n[![PyPI version](https://badge.fury.io/py/ellar-django-module.svg)](https://badge.fury.io/py/ellar-django-module)\n[![PyPI version](https://img.shields.io/pypi/v/ellar-django-module.svg)](https://pypi.python.org/pypi/ellar-django-module)\n[![PyPI version](https://img.shields.io/pypi/pyversions/ellar-django-module.svg)](https://pypi.python.org/pypi/ellar-django-module)\n\n## Introduction\nA simple way to add use Django ORM with Ellar\n\n## Installation\n```shell\npip install ellar-django-module\n```\n\n## Setup\nIf you are starting from scratch, then you need to scaffold a new project with ellar-cli as shown below:\n```shell\nellar new my_project\n```\nScaffolded project structure\n```text\nmy_project/\n├─ my_project/\n│  ├─ apps/\n│  ├─ core/\n│  ├─ domain/\n│  ├─ config.py\n│  ├─ root_module.py\n│  ├─ server.py\n│  ├─ __init__.py\n├─ tests/\n├─ pyproject.toml\n├─ README.md\n```\nAfter scaffolding our ellar application, we need to set up `DjangoModule` in `my_project/root_module.py`\n\n```python\n# my_project/root_module.py\n\nfrom ellar.common import (\n    Module,\n    exception_handler,\n    IExecutionContext,\n    JSONResponse,\n    Response,\n)\nfrom ellar.core import ModuleBase\nfrom ellar.samples.modules import HomeModule\nfrom ellar_django import DjangoModule\n\n\n@Module(\n    modules=[\n        HomeModule,\n        DjangoModule.setup(settings_module=\"my_project.config\")\n    ]\n)\nclass ApplicationModule(ModuleBase):\n    @exception_handler(404)\n    def exception_404_handler(cls, ctx: IExecutionContext, exc: Exception) -\u003e Response:\n        return JSONResponse(dict(detail=\"Resource not found.\"))\n```\n\nThe `DjangoModule` setup requires a string import of django `settings.py` or any file that contains django settings.\nThis is important for django models definitions and django admins views to work properly. But for now, we have used path to ellar config file to avoid some django errors.\n\nIt's also important to note that `DjangoModule` as added a wrapper around django cli tool. To verify this, still on your terminal, run the code below:\n```shell\nellar django --help\n```\nThis should show you the result below:\n```shell\nUsage: Ellar, Python Web framework django [OPTIONS]\n\n  Ellar will always intercept and command with '--help'.\n\n  So if you want to get help on any django command, simply wrap the command\n  and --help in quotes\n\n  For example: ellar django 'migrate --help'\n\nOptions:\n  --help  Show this message and exit.\n```\n### Scaffolding Django Project\nNow that django cli works, we need to scaffold a django project. why? \nBecause we need `settings.py` and `url.py` provided by django `startproject` command but if you can create these files yourself and link them, \nthen I don't think you need this section.\n\nOn the same terminal, run the command below:\n```shell\nellar django startproject wsgi_django .\n```\nIn the command above, we specified `.` as the current directory to avoid creating a nested directory.\nAlso, we need to delete `manage.py`, `wsgi.py`, `asgi.py` and leave only `settings.py` and `url.py`\n\nCurrent project structure \n```text\nmy_project/\n├─ my_project/\n│  ├─ apps/\n│  ├─ core/\n│  ├─ domain/\n│  ├─ config.py\n│  ├─ root_module.py\n│  ├─ server.py\n│  ├─ __init__.py\n├─ tests/\n├─ wsgi_django/\n│  ├─ settings.py\n│  ├─ urls.py\n│  ├─ __init__.py\n├─ pyproject.toml\n├─ README.md\n```\n\n### Update DjangoModuleSetup\nNow, we have a `settings.py` with all required django settings in `wsgi_django.settings`. So lets apply that to `DjangoModule` setup.\n\n```python\nfrom ellar.common import (\n    Module,\n    exception_handler,\n    IExecutionContext,\n    JSONResponse,\n    Response,\n)\nfrom ellar.core import ModuleBase\nfrom ellar.samples.modules import HomeModule\nfrom ellar_django import DjangoModule\n\n\n@Module(\n    modules=[\n        HomeModule,\n        DjangoModule.setup(settings_module=\"wsgi_django.settings\", path_prefix='/-django-example')\n    ]\n)\nclass ApplicationModule(ModuleBase):\n    @exception_handler(404)\n    def exception_404_handler(cls, ctx: IExecutionContext, exc: Exception) -\u003e Response:\n        return JSONResponse(dict(detail=\"Resource not found.\"))\n```\n### Django Database Migration\nIt's about time to create some database. So as usual, we use django `migrate` command\n\n```shell\nellar django migrate\n```\n\nOutput:\n```shell\nOperations to perform:\n  Apply all migrations: admin, auth, contenttypes, sessions\nRunning migrations:\n  Applying contenttypes.0001_initial... OK\n  Applying auth.0001_initial... OK\n  Applying admin.0001_initial... OK\n  Applying admin.0002_logentry_remove_auto_add... OK\n  Applying admin.0003_logentry_add_action_flag_choices... OK\n  Applying contenttypes.0002_remove_content_type_name... OK\n  Applying auth.0002_alter_permission_name_max_length... OK\n  Applying auth.0003_alter_user_email_max_length... OK\n  Applying auth.0004_alter_user_username_opts... OK\n  Applying auth.0005_alter_user_last_login_null... OK\n  Applying auth.0006_require_contenttypes_0002... OK\n  Applying auth.0007_alter_validators_add_error_messages... OK\n  Applying auth.0008_alter_user_username_max_length... OK\n  Applying auth.0009_alter_user_last_name_max_length... OK\n  Applying auth.0010_alter_group_name_max_length... OK\n  Applying auth.0011_update_proxy_permissions... OK\n  Applying auth.0012_alter_user_first_name_max_length... OK\n  Applying sessions.0001_initial... OK\n```\n\n### Start Server\nNow, that we have everything setup, we can start the server\n```shell\nellar runserver --reload\n```\nIn the above example, we added `/-django-example` as path prefix. This is important because we need to group all django admin views \nwith a prefix and also to avoid unnecessary `Page Not Found` errors.\n\nWe can visit [http://localhost:8000/-django-example/admin](http://localhost:8000/-django-example/admin) to see django Admin UI.\n\n### Serving Django Static Files\nIf you visited the Django Admin view, you will notice the css and javascript files all returned 404 error.\nTo fix this we need to install `whitenoise` package.\n\n```shell\npip install whitenoise\n```\n\nAfterward, we update the django settings with whitenoise middleware as shown blown\n```python\n...\n\nMIDDLEWARE = [\n    \"django.middleware.security.SecurityMiddleware\",\n    \"whitenoise.middleware.WhiteNoiseMiddleware\",\n    ...\n]\nWHITENOISE_STATIC_PREFIX = '/static/'\n...\n```\nSo when you visit [http://localhost:8000/-django-example/admin](http://localhost:8000/-django-example/admin) again, the page should be functional.\n\n### Creating a Superuser\nAs you can see, we need to login to access the admin view. A quick way to do this is by creating\na superuser using `createsuperuser` command. So lets do this below:\n```shell\nellar django createsuperuser\n```\nFollow the prompts and use the created credentials to log in to django admin panel.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-ellar%2Fellar-django-module","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpython-ellar%2Fellar-django-module","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-ellar%2Fellar-django-module/lists"}