1. Create / Start a new web project
- cmd: django-admin startproject project_name
- cmd: cd project_name
- cmd: python manage.py startapp application_name
- under application_name folder, create a new file urls.py
- open views.py under application_name folder, create a view:from django.shortcuts import renderdef example_view(request):return render(request, 'my_app/example.html')#refer to my_app/templates/my_app/example.html
- in the urls.py under application_name, connect to view to the url:from django.urls import pathfrom . import viewsurlpatterns=[path('', views.example_view, name = "example_page")]
- in the project_name folder, open urls.py, import "include", and include the application_name urls:from django.contrib import adminfrom django.urls import path, includeurlpatterns = [path('admin/', admin.site.urls),path('my_app/', include('my_app.urls')),]
- at project level, cmd: python manage.py migrate
- at project level, go to settings.py, in the session of INSTALLED_APPS, add the AppConfig (check the name in apps.py in the application folder). don't forget the commaINSTALLED_APPS = ['my_app.apps.MyAppConfig','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',]
- at project level, cmd: python manage.py makemigrations application_name. At later stage, after making changes, cmd: python manage.py migrate
- at application level, create a new folder called "templates". in the "templates" folder, create a folder called application_name, and put html files in it.
- at project level, cmd: python manage.py runserver