Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is creating an accounts app in Django a good practice?

I am wondering if creating an accounts app in Django is a good practice.

Say you have a Django project named mysite and you create inside two apps: core, which holds some business logic, and accounts.

mysite/accounts/urls.py

urlpatterns = [
    url('^', include('django.contrib.auth.urls')),
]

mysite/mysite/urls.py

urlpatterns = [
    url(r'^accounts/', include('accounts.urls')),
    url(r'^core/', include('core.urls')),
]

mysite/accounts/templates/registration/login.html

{% extends "base.html" %}

{% block content %}
{# Content of login page #}
{% endblock %}

mysite/core/templates/base.html

<!DOCTYPE html>
<html>
<body>
    {% block content %}{% endblock %}
</body>
</html>

And I create all the other necessary templates for the views in django.contrib.auth.urls.

Of course we don't forget to plug the two apps:

mysite/mysite/settings.py

INSTALLED_APPS = [
    'accounts.apps.AccountsConfig',
    'core.apps.CoreConfig',
    # ...
]

Is all of this good practice or should I integrate the whole accounts and authentication management in the core app?

like image 755
Fred Avatar asked Feb 11 '17 23:02

Fred


1 Answers

This is very dependent on your personal preferences, but I would say that accounts definitely deserve separate app.

However, I wouldn't put any business logic into the core app. Core app usually contains some shared utils, mixins, templates, abstract models, which are used in multiple other apps. Specific business logic should be implemented in separate app(s).

If you can get your hands on https://www.twoscoopspress.com/products/two-scoops-of-django-1-8, it describes this kind of setup in more details.

like image 105
ozren1983 Avatar answered Oct 13 '22 16:10

ozren1983