-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDjango_commands.txt
151 lines (85 loc) · 4.17 KB
/
Django_commands.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# TO Create virtual environment in Window.
pip install virtualenv - kind of room
virtualenv env (env is folder as room)
cd env/scripts/activate (to activate env, everytime you have to do)
# TO Create virtual environment in Linux.
cd path/to/your/project
python3 -m venv virtualenviroment_name
source virtualenviroment_name/bin/activate
# To Install all package in requirment.txt
pip install -r requirements.txt
# To run build.sh file.
bash build.sh
# To Create superuser for Django admin
python manage.py createsuperuser
# To change password and forget username of superuser
python manage.py shell
from django.contrib.auth.models import User
users = User.objects.all()
print(users)
python manage.py changepassword <username>
#To delete superuser
python manage.py shell
from django.contrib.auth.models import User
User.objects.all()[0].delete() (it will delete user which is at 0 index)
# To add Google Signin option;
https://youtu.be/yO6PP0vEOMc?si=u5s_IRff33rWSOZ3
# To start Django Project.
django-admin startproject project_1
python manage.py startapp home (to make home as new features in the application inside your core directory)
python manage.py startapp account (to make home as new features in the application inside core directory)
python manage.py runserver 0.0.0.0:5000 (TO run server/ at specific port, it will be run inside the core directory)
don't forget to add apps in settings.py
view.py of every app is logical part from where we can send data from backend to frontend.
templates ke ander index.html banaoge then wo automatic detect kar lega.
(templates should be inside your app(like: home, contacts etc.)
context = {'peoples': peoples} ; for sending data from backend to frontend. (write this in the return of the home function of views)
python manage.py makemigrations (after writing in the file of model.py of app)
python manage.py migrate (detabse ke ander deta dikhne lagega)
what if we delete a migration file ()
python manage.py shell -> import file -> Then you can put student(data) then student.save() to save data in the database.
x = Student(name = "nag", age = 22, email = "[email protected]")
x.save()
Student.objects.all()
Student.objects.all()[0].name
Student.objects.all()[0].id
if you want to run a function inside a file which is using some resources of django then you can run this function using shell.
(first import that file in shell then call that function).
search django shell.
CRUD Operation:
Three method to create data in Car class.
1. car = Car(name = 'bmw', speed = 120)
car.save()
2. Car.objects.create(name = 'audi', speed = 150)
(no need to save)
3. Car.objects.create(**car_dict)
where car_dict is a dictonary contain name and spped as key and its value).
Read:
Car.object.get(id=100) , if id not present then it will through error.
Car.object.get(id=100) , if id is not present then it will return empty.
Update method;
x = Car.object.get(id = 1)
x.name = "Creata"
x.speed = 200
x.save()
or
Car.objects.filter(id = 1).update(name = 'dfg')
Delete;
Car.object.get(id = 1).delete()
Car.object.all().delete() , delete all data of car
Note;
1. If you add __str__ method inside Car class and return self.name then it show name during crud operation.
2. To send data from frontend to backend use POST.
3. To send data from backend to frontend use context which is defined in views.py
To see users,
from django.contrib.auth.models import *
User.objects.all()[0].username
To see model data;
from home.models import *
Contest.objects.all()[0].name
Title : Byju’s reducing real estate footprint, vacates two offices in Bengaluru.
Desciption : Byju’s has relinquished about 6,20,000 square feet of office space in Bengaluru as the edtech major is looking to slash costs and raise capital amid a series of crises.The terminated office assets include 550,000 sq ft in Kalyani Tech Park in Whitefield and 70,000 sq ft in IBC Knowledge Park, people aware of the matter said. Both these assets were given up between 2022 and 2023.
link: https://economictimes.indiatimes.com/tech/technology/byjus-reducing-real-estate-footprint-vacates-two-offices-in-bengaluru/articleshow/105744500.cms
Search;
django template tags.
django models(diffrent fields).