0% found this document useful (0 votes)
23 views

django short notes

django short notes

Uploaded by

Yash Kadam
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

django short notes

django short notes

Uploaded by

Yash Kadam
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#Django:server side application framework that designed to support the development

of dynamic websites
-it follows principle "Dont repeat yourself"
-it also follows MVT architecture-model-view-template architecture

# MVT:
model:used for storing and maintaining your data,it is backend where DB is defined
view:all about presentation
templates:template for user interface

in Django job of controller i.e, business logic,routes,etc., is taken care by


Django itself ,it is inbuilt.

****************************commands:*******************************************
1. django-admin startproject projectname - to create new Django project
cd projectname -change directory to project

2. python manage.py runserver -to start server

-project will have one more folder inside it named same as project it will have :
1.setting.py -
which will contain all information about automatically provided
subapplications,databases info ,middlewares,etc
2.urls.py -
it contains all the urls required
3.wsgi.py-
which stands for web server gateway interface, helps Django serve our
eventual web
pages.
4.manage.py-
is used to execute various Django commands such as running the local web
server
or creating a new app.

*********************procedure for creating sub


application(pages):************************

# python manage.py startapp pages- to create sub application

step1:create sub application by running this command on your project directory


step2:register the sub application to INSTALLED_APPS[] in settings.py using
classname mentioned in apps.py of sub application
ex.INSTALLED_APPS[
'pages.apps.PagesConfig',
]
step3:create urls.py file inside sub application to write all the urls regarding
the sub application
step4:define view of application in view.py
step5:include application url in main urls.py file
ex:urlpatterns = [
path('', include('pages.urls')),
]

********************static folder**********************************
1.create a static folder inside project:
2.download bootstrap 5.0
3.extract css and js folders inside static folder
run the command:python manage.py collectstatic
update the STATIC_URL inside settings.py
ex.
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
STATICFILES_DIRS = [
os.path.join(BASE_DIR,'helloworld/static')
]

*********************templates*************************************

1.create a folder template


2.inside it create a folder pages
3.inside pages we will create html pages whose path is given in urls.py of
pages(sub application)
4.register template folder in TEMPLATES in settings.py as base directory as
'DIRS': [os.path.join(BASE_DIR,'templates')]:
ex:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],

***********************adding css and js*****************************

1.create a base.html file inside templates outside pages of templates


2.copy the base.html of github.com/kpagariya/garware to our base.html
3.update the required page names inside base.html after copying

*****************connecting to database******************************

configure the database in settings.py


DATABASES = {
'default': {
#'ENGINE': 'django.db.backends.sqlite3',
#'NAME': 'BASE_DIR/'db.sqlite3',

'ENGINE': 'django.db.backends.mysql',
'NAME': 'django',
'USER' : 'root',
'HOST' : 'localhost',
'PASSWORD' : 'your_password',
'PORT' : '0303',
}
}

** 4. python manage.py migrate


-this command is used to create default tables in the database that u have
connected to Django project it will create some default tables
-run the command in project directory on terminal

1.then go to MySQL prompt(MySQL command line client):


use the MySQL commands to create,use and show databases and tables;
commands are:
1.create database djangodb;
2.use djangodb;
3.show tables; -after migrate command it will create following tables in
database
we created through MySQL prompt:
+----------------------------+
| Tables_in_django |
+----------------------------+
| auth_group |
| auth_group_permissions |
| auth_permission |
| auth_user |
| auth_user_groups |
| auth_user_user_permissions |
| django_admin_log |
| django_content_type |
| django_migrations |
| django_session |
+----------------------------+

**after this run a command:


5. python manage.py createsuperuser

-this command will create superuser with referred name and password

C:\Users\Asus\demo>python manage.py createsuperuser


Username (leave blank to use 'asus'): admin
Email address:
Password:
Password (again):
The password is too similar to the username.
This password is too short. It must contain at least 8 characters.
This password is too common.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.

**superuser will be created then run server and login as admin with the given
username and password:
you can create new users using add user and add new user with password and details.

## python manage.py makemigrations -command:


use to convert the types of models from Django python to required database for ex
in our case it is MySQL

##python manage.py migrate -command:


use to shift the python code to database(creating tables,etc)

##models.py -
use to create models related to our tables then using make migrations command we
change the types of Django or python to databse language
and then migrate command will create the tables of that model

## pip install pillow -command:


this command is used to create tables on the basis of models

## auth_user=user details
django_session=session details

You might also like