Starting a project in Django

Process by process steps for better understanding.

  1. Install all the setup and requirements to start a Python project.
python3 -m pip install django
  1. After installing Django and pip, Please refer to the instalment of the Django and pip in the attached document.

https://docs.djangoproject.com/en/4.2/topics/install/

Now starting a project in Django:

  1. Run the code: django-admin startproject CRM

  2. After that run the command: : django-admin startapp Website

  3. After that your vs code will look similar like this:

  1. After that setup then create the urls.py file in your app file. In this scenario Website is the app and CRM is the project.

  2. Lets setup our urls files: CRM URLS

from django.contrib import admin
from django.urls import path , include 

urlpatterns = [
    path('admin/', admin.site.urls),
    path ('', include('Website.urls')),
]
  1. After that setup the urls file of our APP: Website as shown below:
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name = 'home'),

]
  1. After this setup, dont forgot to register your app in the setting.py file in Project.
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'Website',

]
  1. After this setup your views so that it can render the file.
from django.shortcuts import render

# Create your views here.


def home(request):
    return render(request, 'home.html', {})
  1. For that create new folder templates and create home.html in that folder in the app. In this scenerio Website as shown below:

  1. After that it will render your file while loading. For that run python3 manage.py runserver. You can run this command before all this steps.

    to create a superuser you can run the command: python3 manage.py createsuperuser