SUMMARY
The closest to django apps in phoenix are contexts (when comparing the frameworks and not the ecosystem of python/elixir). Django apps could be “self-contained” (not necessarily though). They could include models, views, migrations, templates, urls, etc, and they could have everything they need to run inside a django project. Contexts, on the other hand, mainly contain the logic + schemas/models.
DETAILS
Keep in mind that what I’m going to write here is the default for both frameworks. Phoenix is way more flexible than django when it comes to folder/file structure.
django:
django-admin startproject project_name
cd project_name
django-admin startapp app_name
In django, you usually define the models inside app_name/models.py
and probably add app_name
to the list of INSTALLED_APPS
in settings.py
phoenix:
mix phx.new project_name
cd project_name
mix phx.gen.html app_name model_name table_name field_one:string field_two:integer field_three:boolean
This generates a folder named app_name
and a file called app_name.ex
(context), both under the project_name/lib/project_name/
folder. The app_name
folder contains your schemas or “models”. It will also generate the routes and migration files when necessary.
Example. Assuming you are inside a blog
project:
mix phx.gen.html Accounts User users username:string email:string
would generate:
blog/lib/blog/accounts.ex
blog/lib/blog/accounts/user.ex
In django, the app has all the views and urls, etc. In phoenix, controllers (views in django) and routers (urls in django) are in separate places. All controllers are grouped together and all routes are usually in one file router.ex
.
Also in phoenix, you have more options for generating different kinds of contexts out of the box. For example, you have phx.gen.html
to generate an endpoint that deals with html, phx.gen.json
to generate a json endpoint, phx.gen.schema
to generate only the schema (model) with no views or urls, etc.
I’m sure I missed something while writing all this, but let me know if you need more/better explanations.