You are on page 1of 2

1. Django is a python framework that helps in making web applications. It is full-stack framework.

2. To install Django, run pip install Django on Command-line prompt.


3. In order to make a project, we need to run Django-admin startproject <project name>. This will
create a set of files that we will need to start our project.
4. In order to run the server, we need to move to our project folder and run python manage.py
runserver in our terminal.
5. These two commands helped me to get rid of migration warnings in Django:
a. python manage.py makemigrations: It detects if there is any change in the database
schema
b. python manage.py migrate: It sets up a default table that can be used in default
authentication that Django provides.

6. Django uses MVT (Model View Temperature) architecture. The Model helps to handle database.
... The View is used to execute the business logic and interact with a model to carry data and
renders a template.
7. To initiate an app, we will run python manage.py startapp <app name>. This will create an app
of our desired name in our project.
8. URL dispatching is a simple way to map URLs to view code using a simple pattern matching
language. In Django, it is done through url files in our project and apps.
9. Static files are files that clients download as they are from the server. We keep our static files in
the static folder and manage the directory is settings.py for our static files. Do not keep sensitive
file in static files as only public files are included here.
10. A template is rendered with context.
11. In order to create a superuser that has all the privileges, we have to run python manage.py
createsuperuser and fulfil the needed credentials for our superuser.
12. Template inheritance is an approach to managing templates that resembles object-oriented
programming techniques. It is done by using extends, blocks, endblocks and tools like these.
13. A CSRF token is a unique, secret, unpredictable value that is generated by the server-side
application and transmitted to the client in such a way that it is included in a subsequent HTTP
request made by the client. The CSRF tokens are inserted by csrf_token block.
14. For forms, Django detects the type of form input from the attribute named name.
15. Model in Django defines our database. One class in our model is kind of a table in database.
16. makemigrations is responsible for packaging up your model changes into individual migration
files - analogous to commits - and migrate is responsible for applying those to your database.
17. We can use python manage.py shell in order to check objects of our database runtime. We can
run queries, can instances and other things using shell command. Below are some simple
queries that we can run:
a. In order to check the objects of a specific “table”, we need to import it first from our
models. Like, in our case, it is going to be from home.models import Contact where
Contact is our model name. We will run all commands on our model named Contact.
b. To see all the objects in Contact, we will run Contact.objects.all().
c. We can use indexing to get a specific entry. Like Contact.objects.all()[0] fetches the first
object.
d. We can access a specific entry’s attribute as well. For example,
Contact.objects.all()[0].email fetches the email of the first entry.
e. We can filter out specific objects (like a query) too. For instance,
Contact.objects.filter(name=”Saad”, phone=”132”) runs the query and fetches all the
results that match the query.
f. To change the results of a query, we can create an instance of the results, modify and
save them so that our results are changed.
g. For further queries, we need to check the documentation of Django
Things followed from tutorial:
1. We ran our server and saw the website what it looked like which showed that our server has been
successfully started.
2. We first edited urls.py file. Here, we directed the ‘admin/’ path to admin.site.urls.
3. Then, we created our app using the startapp command. The app we created was named as
home.
4. We created a superuser using the createsuperuser command in order to make an admin that
can access the admin/ path.
5. Next, we edited the admin portal a little bit by changing admin.site.<property name> in urls.py.
6. After the creation of home app, we edited the main urls.py and edited the urlpatterns in case
when some brings an empty path to the website.
7. Then, we created a urls.py in our home app. It included the direction to which all the incoming
paths will be directed to (mainly, they will be sent to the views function where a function in
views.py will be executed on a specific path). We created multiple such paths.
8. Next, we created all the functions in our views.py. Views.py includes all the functions that will
render something when a request comes to them. At first, we created simple HttpResponses to
test our functions.
9. Now, we are ready to create our static and template files. For that, we first created two folders
named static and templates. Then, we put the static files in our static folder.
10. After this, we test how to pass variables to an html file and render the context from views.py.
11. Next, we created html files with the help of bootstrap in templates folder. We used blocks to
render certain html blocks. We are to design these files whatever the way we like.
12. We introduced CSRF tokens to enable secure form submissions.
13. Now, we have to introduce models in order to store entered data in our database. For this, we
created Contact model in our models and then registered it in admin of our app using
admin.site.register().
14. After registration of our model, we need to insert our app name from apps.py (in our case it is
HomeConfig, the apps.py from the home app) in the project’s setting’s installed apps. After that,
we are ready to makemigrations and register our database.
15. After making migrations, we are ready to migrate. To do that, we need to run python manage.py
migrate. It will generate a table.
16. Next, we are going to edit our views.py in order to fetch all the information entered in our form
and create an object out of it and save that object.
17. Each form is stored at the Django admin as an object. In order to change the display name of the
project, we need to define def __str__ (self): return self.name so that the display now is the
name of the person that has filled the form.
18. On submission of a form, we need to display an alert. To do that, we are going to add a
dismissible alert in our base.html.
19. Next, we are going to iterate the messages coming from views.py (using from django.contrib
import messages), and display them at our base.html if any message/s are received. For this,
we need to introduce the Django blocks of if, endif, for, endfor, and variables as {{message}},
{{message-tag}} etc.

User Creation, Login, Logout, Sign Up etc.


The library to include to create users is: from Django.contrib.auth.models import User. The User class
features many functionalities that involve permissions, authentication, login, logout etc.

You might also like