← Back to all tutorials
Django TutorialEpisode 18

Accounts App

Create a separate accounts app — organize user authentication features (signup, login, logout) into their own Django app.

Accounts App

Authentication is a separate concern from articles, so let us create a dedicated accounts app for signup, login, and logout.

Creating the App

python manage.py startapp accounts

Registering the App

# djangoblog/settings.py
INSTALLED_APPS = [
    # ... built-in apps
    'articles',
    'accounts',  # Add the accounts app
]

Accounts URLs

# accounts/urls.py
from django.urls import path
from . import views

app_name = 'accounts'

urlpatterns = [
    path('signup/', views.signup_view, name='signup'),
    path('login/', views.login_view, name='login'),
    path('logout/', views.logout_view, name='logout'),
]

Including in Project URLs

# djangoblog/urls.py
urlpatterns = [
    path('admin/', admin.site.urls),
    path('articles/', include('articles.urls')),
    path('accounts/', include('accounts.urls')),
]

Placeholder Views

# accounts/views.py
from django.shortcuts import render

def signup_view(request):
    return render(request, 'accounts/signup.html')

def login_view(request):
    return render(request, 'accounts/login.html')

def logout_view(request):
    # TODO: implement logout
    return render(request, 'accounts/logout.html')

Key Takeaways

  • Create a separate app for authentication — keeps code organized
  • Three core routes: signup, login, logout
  • Use app_name for URL namespacing
  • Django has a built-in User model — you do not need to create one