About Finding Spelling Mistakes in the User's Input

In a management command you can allow to enter an app name and check if there are no spelling mistakes in the user's input with a code like this:

from django.apps import apps
from difflib import get_close_matches

app_labels = [config.label for config in apps.get_app_configs()]
app_label = input("Enter an app name: ")
if app_label not in app_labels:
    close_matches = get_close_matches(app_label, app_labels, n=2)
    if close_matches:
        print(f"Did you mean: {', '.join(close_matches)}?")

Tips and Tricks Programming User Experience Development Accessibility Django 4.2 Django 3.2 Django 2.2 Python 3

Django/Python Consulting

If you have a specific Django challenge or integration you'd like to solve, I'd be happy to help. Book a free 30-minute call to discuss your project, see if we're a good fit, and explore the best approach for your needs. After the call, you'll receive a tailored cost estimate based on what we discuss.