Initialize a new Django project, starting from an empty directory with just the bare minimum steps and no fluff.
Prerequisites
You must have these installed to begin.
Note: If this is your first Django project, begin with a tutorial instead. The official Django tutorial covers everything below and more in detail.
Initialize Python Project
Starting from an empty directory for your new project, initialize the Python project.
uv init --no-package --app .
No need for the main.py file.
rm main.py
Install Django.
uv add django
Initialize Django Project
Create the Django project files, using project as the folder name.
uv run django-admin startproject project .
Create a Django app called "core".
uv run manage.py startapp core
Add core to INSTALLED_APPS in project/settings.py.
INSTALLED_APPS = [
...,
"core",
]
Running the development server should now display the Django launch page at http://127.0.0.1:8000/.
uv run manage.py runserver
Create a View
Add a new view to core/views.py.
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello World!")
Route view to be the front page in core/urls.py.
from django.urls import path
from core import views
urlpatterns = [
path("", views.index, name="index"),
]
Include core url patterns in project/urls.py:
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path("", include("core.urls")),
]
With runserver still running, refresh http://127.0.0.1:8000/ to see your new view.
Next Steps
- Edit
pyproject.tomlwith project name and description. - Pick a database.
- Configure a custom user.
- Run migrations.
- Add your favourite third-party Django packages.
- Install and configure linters and formatters.
- Add a
base.htmltemplate.
Getting Help
For help with starting your project visit the wonderful community in the Django Forum or the Django Discord Server (I like to hang out here).