-
🌿 django-admin startproject project-name
-
open the project-name 🌿 python manage.py makemigrations 🌿 python manage.py migrate
python manage.py startapp home
-
Resister [app] After my [app] has been created (home)
-
home/apps.py copy function name "HomeConfig" and paste it in the [project] (usersproject)
-
usersproject/settings.py Installed_apps= [ 'home.apps.HomeConfig', ]
🌿 python manage.py startapp home
-
-
Allowed_hosts =[] usersproject/settings.py define the allowed hosts = ["http://localhost:8000, "satyam.com"] else it will throw an error
-
create an static and templates folder
- home
- usersproject
- static
- templates
-
set static dirs in django usersproject/settings.py at the end paste this STATICFILES_DIRS = [ os.path.join(BASE_DIR ,"static"), ]
-
set templates usersproject/settings.py update : 'DIRS': [os.path.join(BASE_DIR ,"templates"),],
-
Create the html files
- templates/index.html
- templates/login.html
-
update the userproject/urls.py
-
from django.urls import path => from django.urls import path , include
-
urlpatterns = [ path('admin/', admin.site.urls),
path('', include('home.urls')), ]
-
[app] home create a new file name home/urls.py : this will handle all of the home files routing
home/urls.py from django.contrib import admin from django.urls import path , include from home import views
urlpatterns = [ path('', views.index, name="home"), path('login', views.login, name="login"), path('logout', views.logout, name="logout"), ]
-
[app] home/views.py : now i need to create all of the functions too
from django.shortcuts import render, redirect
def index(request): return render(request,'index.html') def login(request): return render(request,'login.html') def logout(request): return render(request,'index.html')
-