Chapter 1: Django Home

Home part of a Django project — the landing page / homepage / welcome screen that users see first when they visit your domain (like example.com/ or 127.0.0.1:8000/).

Many beginners get confused here because the official poll tutorial doesn’t create a nice homepage — it just jumps straight to /polls/. In real projects we almost always want something prettier and more meaningful at the root URL.

I’ll explain this like we’re pair-programming together — slowly, with reasoning, common mistakes, modern 2025–2026 best practices, and several realistic ways people actually do it today.

Quick reality check — what most real projects do in 2025/2026

Style When people use it Pros Cons Folder name people choose
No separate app Very small / micro projects, prototypes Zero extra files Messy urls.py later
pages / core app Most medium projects (very popular) Clean, conventional One more app pages or core
home app Some teams like explicit names Very clear intent Slightly non-standard home
Just TemplateView in project urls.py Landing page = marketing / static-ish page Fastest possible Harder to grow later
landing + marketing tools SaaS startups with hero sections, waitlists Full control over sections Overkill for internal tools landing

Most common & recommended today → create small app called pages or core and put homepage there.

Option 1 – Recommended: Small pages app (clean & scalable)

We continue from your previous project folder (mypolls/ with mysite/ + polls/).

Bash

Add it to INSTALLED_APPS in mysite/settings.py (near ‘polls.apps.PollsConfig’):

Python

Create basic structure inside pages/

text

pages/views.py

Python

Many teams prefer function-based for the absolute simplest homepage — it’s easier to read when you’re learning.

Create pages/urls.py

Python

Connect it in the project mysite/urls.py

Python

Important: put path(”) last — Django reads top-to-bottom. If you put it first, everything else would never match.

Now the template — pages/templates/pages/home.html

First create folders:

text

pages/templates/pages/home.html

HTML

Run server:

Bash

Go to http://127.0.0.1:8000/ → you should see nice welcome page!

Option 2 – Even simpler (no extra app – good for tiny projects)

In mysite/urls.py:

Python

Then create templates/home.html (in project-level templates/ folder — you need to add ‘DIRS’: [BASE_DIR / ‘templates’], to TEMPLATES setting).

This is fast but becomes messy when you want:

  • context processors
  • different logic for logged-in users
  • hero image / stats / testimonials

So most people move to pages app after first weekend.

Option 3 – Very modern minimal landing page (2026 style – Tailwind or Pico CSS)

Many developers now use CDN-based minimal CSS frameworks.

Example with Pico CSS (very light, no build step):

In <head> add:

HTML

Then body becomes:

HTML

Looks surprisingly professional with almost zero effort.

Quick checklist – did I miss anything important?

  • Template folder structure → pages/templates/pages/ (namespaced) prevents name clashes later
  • Use {% url ‘polls:index’ %} — never hardcode /polls/
  • Add name=’home’ → you can use {% url ‘home’ %} in future navbars
  • Consider adding robots.txt, favicon.ico later in the same pages app

Which style should YOU choose right now?

  • Just learning → Option 1 with pages app + function-based view (most readable, teaches app structure correctly)
  • Want fastest result → Option 2 with TemplateView
  • Building real product → Option 1 + add Tailwind/Pico/Bulma via CDN

Try creating the pages version now — it usually takes 8–12 minutes.

Once done, come back and tell me:

  • Did it work?
  • Want to add login/logout links?
  • Want nice navbar that appears on all pages?
  • Or continue to polls detail + voting page?

I’m right here 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *