Creating a Django Project
A Django project is created with a single command, django-admin startproject mysite, which generates a directory containing manage.py and an inner package also named mysite holding four key files: settings.py, urls.py, wsgi.py, and asgi.py. This one command scaffolds the entire skeleton a Django site needs before a single line of application code is written, which is why it's the very first step in any Django tutorial and any real production project alike.
Cricket analogy: Similar to how groundstaff prepare a pitch, boundary rope, and sightscreens before a single ball is bowled at a venue like the MCG, django-admin startproject prepares settings.py, urls.py, and manage.py before a single line of application code is written.
Understanding the Generated Files
manage.py is a command-line utility used for administrative tasks like runserver, migrate, and startapp, and it works by setting the DJANGO_SETTINGS_MODULE environment variable before delegating to Django's internal command-line tooling. settings.py centralizes configuration, including INSTALLED_APPS (which apps are active), DATABASES (connection details, SQLite by default), MIDDLEWARE (a list of hooks that process every request/response), and ALLOWED_HOSTS (which domains may serve the site) — a value that must be set correctly in production or Django will reject incoming requests with a 400 error.
Cricket analogy: Similar to how the match referee's rulebook lists every regulation governing a fixture, settings.py lists every configuration a Django project needs — INSTALLED_APPS, DATABASES, ALLOWED_HOSTS — in one central file.
Running the Development Server
python manage.py runserver starts Django's lightweight built-in web server, typically listening on http://127.0.0.1:8000/, and is intended purely for local development — it is single-threaded by default, has no production-grade security hardening, and Django's own documentation explicitly warns against using it in production. Visiting the URL immediately after startproject shows Django's default 'The install worked successfully' congratulations page, confirming settings.py is valid and the WSGI application can be served, before any app-specific views have been added.
Cricket analogy: Similar to a warm-up net session before an actual match at a venue like Eden Gardens, runserver is meant purely for local development — Django's docs explicitly warn against using it as the 'match-day' production server.
django-admin startproject mysite
cd mysite
python manage.py runserver
# Visit http://127.0.0.1:8000/ to see Django's success page
# Generated structure:
# mysite/
# manage.py
# mysite/
# __init__.py
# settings.py
# urls.py
# wsgi.py
# asgi.pyNever run runserver to serve real production traffic. It is single-threaded, lacks production security hardening, and Django's documentation explicitly recommends a WSGI/ASGI server like Gunicorn or Daphne behind Nginx for production deployments.
django-admin startproject mysitescaffolds a new Django project skeleton.manage.pyis the command-line utility for admin tasks likemigrateandrunserver.settings.pycentralizesINSTALLED_APPS,DATABASES,MIDDLEWARE, andALLOWED_HOSTS.urls.pyis the project-level URL configuration entry point.python manage.py runserverstarts a local-only development server on port 8000.- The default database backend is SQLite unless
DATABASESis reconfigured. runservermust never be used in production; use Gunicorn or Daphne instead.
Practice what you learned
1. Which command creates a new Django project?
2. What is the default database backend when a Django project is first created?
3. What happens if a request's Host header isn't listed in ALLOWED_HOSTS in production?
4. Which command starts Django's built-in development server?
5. Why should `runserver` never be used in production?
Was this page helpful?
You May Also Like
What Is Django?
An introduction to Django, the high-level Python web framework that ships with an ORM, admin site, and authentication built in, so teams can move from idea to working application quickly.
Django Apps Explained
Why Django separates a project into reusable 'apps', how to create one with startapp, and how to register it so Django picks up its models and views.
The MVT Architecture
How Django splits an application into Models, Views, and Templates, and how the framework itself acts as the controller that wires the three together on every request.
Related Reading
Related Study Notes in Web Development
Browse all study notesWebSockets Study Notes
Web Development · 30 topics
Web DevelopmentWebAssembly Study Notes
WebAssembly · 30 topics
Web DevelopmentgRPC Study Notes
Protocol Buffers · 30 topics
Web DevelopmentSpring Boot Study Notes
Java · 30 topics
Web DevelopmentFlask Study Notes
Python · 30 topics
Web DevelopmentNext.js Study Notes
JavaScript · 30 topics