Skip to content

Instantly share code, notes, and snippets.

@mkushal10
Last active August 10, 2024 14:53
Show Gist options
  • Select an option

  • Save mkushal10/addc0d7c0e86180e4ecf6c486c8f96de to your computer and use it in GitHub Desktop.

Select an option

Save mkushal10/addc0d7c0e86180e4ecf6c486c8f96de to your computer and use it in GitHub Desktop.
1. Go to the https://www.python.org/downloads/ and Download lastest Python.
☑ Install launcher to all users
☑ Add Python 3.9 to PATH
-->Click Next Button
2. Check some
☑ Documentation
☑ pip
☑ td/tk and IDLE
☑ Python test suite
☑ py launcher ☑ for all users
-->Click Next Button
3. Advanced Options
☑ Install for all users
☑ Associate files with Python
☑ Create shortcuts for installed applications
☑ Add Python to environments variables
☑ Precompile standard library
Customize install location
C:\Python39
-->Click Next Button
4. At last, Click the Disable path length limit.
5. Let's Check the Python
>>Enter-python - To check the python is installed or not
>>exit() - To exit
6. To see the installed package
>>pip freeze
7. To install Django -- To install Gobally
>>pip install django
8. To see the installed package
>>pip freeze
1. To create a new project
django-admin startproject projectname
2. Project Structure
projectname/
manage.py
projectname/
__init__.py
settings.py
urls.py
asgi.py
wsgi.py
These files are:
- The outer projectname/ root directory is a container for your project. Its name doesn’t matter to Django; you can rename it to anything you like.
- manage.py: A command-line utility that lets you interact with this Django project in various ways. You can read all the details about manage.py in django-admin and manage.py.
a. To run the server. Migrations comes under this. It helps us to manage the project.
- The inner mysite/ directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. projectname.urls).
- projectname/__init__.py: An empty file that tells Python that this directory should be considered a Python package.
- projectname/settings.py: Settings/configuration for this Django project. Django settings will tell you all about how settings work.
- projectname/urls.py: The URL declarations for this Django project; a “table of contents” of your Django-powered site. You can read more about URLs in URL dispatcher.
- projectname/asgi.py: An entry-point for ASGI-compatible web servers to serve your project.
- projectname/wsgi.py: An entry-point for WSGI-compatible web servers to serve your project.
- projectname: This is also an app given by django default.
1. To run the server
python manage.py runserver
2. To change the port
python manage.py runserver 4444
python manage.py runserver port_number
1. Make a "static" folder for css, js files
2. Make a "templates" folder for html files
3. Make a "media" folder for storing dyanamic images, files, etc.
It manages datbase and all.
1. from pathlib import Path #importing Path function
2. BASE_DIR = Path(__file__).resolve().parent.parent #through Path, Directory ko path nikalaleko
3. SECRET_KEY = 'django-insecure-40&2(0+j59578*!2bvo9qy9l#ik#eok++ilq@^c_=1!2%#rn9u' #It generates when the project is created.
4. DEBUG = True #True needed while development to show the errors.
5. ALLOWED_HOSTS = [] #to pass the host
6. INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
] #All the default tables and you can add installed apps
7. MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
] #for the restriction by django/Security process
8. ROOT_URLCONF = 'kushtech.urls' #defined url path
9. TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
10. WSGI_APPLICATION = 'kushtech.wsgi.application'
11. DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}#database setup
12. AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]#for password validation
13.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment