django short notes
django short notes
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
****************************commands:*******************************************
1. django-admin startproject projectname - to create new Django project
cd projectname -change directory to project
-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.
********************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*************************************
*****************connecting to database******************************
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django',
'USER' : 'root',
'HOST' : 'localhost',
'PASSWORD' : 'your_password',
'PORT' : '0303',
}
}
-this command will create superuser with referred name and password
**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.
##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
## auth_user=user details
django_session=session details