Apps and Routes

Split Westloop into accounts, posts, and social apps and wire the first URL patterns.

Goal for this part

Split Westloop into three Django apps and wire the first named routes. A social network is not one views.py. Accounts, posts, and the follow graph change at different speeds, so they live in different apps.

Why three apps

accounts owns registration, login, profiles, and avatars. posts owns the update text, likes, and comments. social owns follows, the following timeline, search, and notifications. Cross-app imports are fine; dumping every model into one app is how tutorials turn into unreadable files.

Walkthrough: start the apps

python manage.py startapp accounts
python manage.py startapp posts
python manage.py startapp social

Register them in INSTALLED_APPS before you write models later. Django only migrates apps it knows about.

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "accounts",
    "posts",
    "social",
]

Give each app its own urls.py and include them from the project. Placeholder views return plain text so you can prove routing before templates exist.

# westloop/urls.py
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path("admin/", admin.site.urls),
    path("", include("posts.urls")),
    path("", include("accounts.urls")),
    path("", include("social.urls")),
]
# posts/urls.py
from django.urls import path
from . import views

app_name = "posts"
urlpatterns = [
    path("", views.feed, name="feed"),
    path("p/<slug:slug>/", views.detail, name="detail"),
]

How to run it and what you should see

Start the snapshot and open /, /accounts/login/, and /search/. You should see short placeholder responses, not 404s. Named routes now exist for every later template {% url %} tag.

Common mistakes

Forgetting app_name breaks namespaced URLs like posts:feed. Including an app’s URLs before creating urls.py raises ModuleNotFoundError. Two apps claiming the same path is last-include-wins — keep account paths under /accounts/ and search under /search/.

Try this

Add a named health route that returns the text ok. You will reuse that path as the Nginx health check on the VPS.