Put a basic website online for a cafe

· 5 min read

A cafe, a barber or a tradie does not need a web shop or a login system. They need a page that shows up when someone searches their name, says what they sell, when they are open and where they are, and that the owner can change without calling a developer. A tiny Django site does that well, and the Django admin is the editor.

This guide builds the core of such a site and puts it online. The shape is deliberately plain: a settings record, a menu split into sections and items, and three public pages.

What the owner gets

The owner opens /admin/, signs in, and sees a short list: Site settings, Menu sections (with the items inside), and perhaps a notice for specials. They type, press Save, and the website changes at once. There is no theme, no plugin and nothing to update.

The models

Start a Django project, add an app called shop, and write these models:

from django.db import models


class SiteSettings(models.Model):
    name = models.CharField(max_length=80)
    tagline = models.CharField(max_length=160, blank=True)
    phone = models.CharField(max_length=40, blank=True)
    address = models.CharField(max_length=200)
    opening_hours = models.TextField(help_text="One line per day, for example: Mon to Fri 7am to 3pm")

    class Meta:
        verbose_name_plural = "site settings"

    def __str__(self):
        return self.name


class MenuSection(models.Model):
    title = models.CharField(max_length=80)
    order = models.PositiveSmallIntegerField(default=0)

    class Meta:
        ordering = ["order", "title"]

    def __str__(self):
        return self.title


class MenuItem(models.Model):
    section = models.ForeignKey(MenuSection, on_delete=models.CASCADE, related_name="items")
    name = models.CharField(max_length=100)
    description = models.CharField(max_length=200, blank=True)
    price = models.DecimalField(max_digits=6, decimal_places=2)
    available = models.BooleanField(default=True)

Register them so the owner can edit items inside their section on one screen:

from django.contrib import admin

from .models import MenuItem, MenuSection, SiteSettings


class MenuItemInline(admin.TabularInline):
    model = MenuItem
    extra = 1


@admin.register(MenuSection)
class MenuSectionAdmin(admin.ModelAdmin):
    list_display = ("title", "order")
    inlines = [MenuItemInline]


admin.site.register(SiteSettings)

The pages

Three views are enough: home, menu and contact. The menu view is the one that matters most, because people search for it.

from django.shortcuts import render

from .models import MenuSection, SiteSettings


def menu(request):
    sections = MenuSection.objects.prefetch_related("items")
    return render(request, "shop/menu.html", {"sections": sections, "site": SiteSettings.objects.first()})

In the template, loop over sections, print each section.title as an h2, and under it each item that is available. Use one h1 per page, such as the cafe's name followed by "menu". Put the address and phone number in the page as plain text, not in an image, so people and search engines can read them.

The local business basics

Small businesses win or lose on a handful of things, and most are about being consistent.

  • Same name, address and phone everywhere. Use exactly the same spelling on the site, on your Google Business Profile and on social pages. Mismatches confuse both customers and search engines.
  • Claim a Google Business Profile. For a local business it often matters more than the website. Add the website address to it.
  • A map link, not an embed. A plain link such as https://www.google.com/maps/search/?api=1&query= followed by the url encoded address opens the phone's map app and loads nothing extra into your page.
  • Structured data. Describe the business in a JSON block so search engines know it is a restaurant with an address and phone number:
import json


def restaurant_json(site, url):
    data = {"@context": "https://schema.org", "@type": "Restaurant", "name": site.name, "telephone": site.phone, "address": site.address, "url": url}
    return json.dumps(data).replace("<", "\\u003c")

Print it in the template inside <script type="application/ld+json">. Combine this with a title and description on every page, a sitemap and a robots.txt. The Django SEO guide has the code for all of them.

Settings for production

Use the settings from the Django deploy guide: secrets and DEBUG from the environment, ALLOWED_HOSTS and CSRF_TRUSTED_ORIGINS, the proxy header, WhiteNoise for static files and SQLite at DATABASE_PATH. For a site with a public face and an admin behind it, there is one more cheap setting: once the site answers on https, turn on secure cookies so the admin login never travels in clear text.

SESSION_COOKIE_SECURE = CSRF_COOKIE_SECURE = os.environ.get("SECURE_COOKIES", "") == "1"

Set SECURE_COOKIES=1 on the Environment page after your first successful deploy.

Do not add a contact form unless you need one. A form on a public page invites spam, and a phone number and an email address do the same job for a cafe. Fewer moving parts is a feature here.

Deploy and hand it over

Push the repository to GitHub, create an app on Pharos, set the environment variables and deploy as in the deploy guide. Then, on the app's Overview page, use Create superuser to make the owner's login. Sign in at /admin/, add the settings record, add the menu sections and items, and open the home page.

The data lives in SQLite on the app's persistent folder, so menu edits survive redeploys, and the platform keeps nightly backups of it. Your own domain, such as the cafe's name followed by .com.au, becomes available after the first payment. Until then the site works at its address on the platform's domain, which is fine for testing but not yet for printing on a menu.

Check it before you hand it over

Open the home page on a phone. Check the title, the opening hours, the phone number (does it dial when tapped?) and the map link. Visit /sitemap.xml, /robots.txt and a made up address that should show your own 404 page. The Launch checklist on the app page runs these checks again after each deploy and lists what is missing.

You get a 14-day trial, a card is required to start, and you pay nothing if you cancel before day 14. After that, one app costs A$27 a month. Run through the pre-launch checklist before you share the link.