In this repo, you will learn how to create your first project in Django
VS Code
Python3
Pip
python --version
pip --version
Python3 from https://www.python.org/downloads/
Pip from https://pip.pypa.io/en/stable/installation/
mkdir "Django Project"
cd "Django Project"
Open vs code and type above commands on terminal
python -m venv venv
virtualenv venv
venv\Scripts\Activate
Note: Do Only if you face issue in creating virtualenv, run powershell as a admin
get-ExecutionPolicy
if it give "restricted"
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
Type 'Y' to enable After enabling, run the following command get-ExecutionPolicy Now, it should give "remotesigned"
venv\Scripts\Activate
(now you can see (venv)) in your terminal
pip install django
djagno-admin startproject myproject
cd myproject
python manage.py runserver [port]
Note: here port is optional, by default port is 8000
start localhost:8000/
start 127.0.0.1:8000/
python manage.py runserver 9000
Now it will run our django server with 9000
start localhost:9000/
start 127.0.0.1:9000/
start localhost:8000/admin/
django-admin startapp myapp
Now, Add 'myapp' in INSTALLED_APPS list of setting file of your project 'myapp'.
from django.urls import path
from . import views
# URL endpoints for app
urlpatterns = [
]
from django.urls import path, include
path('myapp/',include('myapp.urls')),
path('',views.index)
from django.urls import path
from . import views
# URL endpoints for app
urlpatterns = [
path('',views.index)
]
from django.shortcuts import render, HttpResponse
# Create your views here.
def index(request):
return HttpResponse("Hello World")
python manage.py runserver
open localhost:8000/myapp/ or 127.0.0.1:8000/myapp/
You have done it. You have successfully created your first app in django.