Python backend

1) Create directory

mkdir fileName


2) Make sure you're in the project directory

cd fileName


3) Create virtual environment

python3 -m venv venv


4) Activate virtual environment

source venv/bin/activate


5) please first those dependency before write insede the requirement.txt

# Install each package separately

pip install Flask

pip install cloudinary

pip install python-dotenv

pip install Flask-CORS


6.0 )  Create Django project

django-admin startproject file_name .


6.1 ) Create weather app

python manage.py startapp fileName



7) Edit file_name/settings.py:


# Add your app to INSTALLED_APPS

INSTALLED_APPS = [

    'django.contrib.admin',

    'django.contrib.auth',

    'django.contrib.contenttypes',

    'django.contrib.sessions',

    'django.contrib.messages',

    'django.contrib.staticfiles',

    'fileName',  # Add this line this is you app name inside the django project

]


# Add REST framework if you want APIs (optional)

INSTALLED_APPS += ['rest_framework']


# Configure templates

TEMPLATES = [

    {

        'BACKEND': 'django.template.backends.django.DjangoTemplates',

        'DIRS': [BASE_DIR / 'templates'],  # Create templates folder

        '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',

            ],

        },

    },

]


# Database (SQLite by default)

DATABASES = {

    'default': {

        'ENGINE': 'django.db.backends.sqlite3',

        'NAME': BASE_DIR / 'db.sqlite3',

    }

}


optional things) Create database tables if you want

python manage.py makemigrations

python manage.py migrate


//now write you code and logic and other thing on your application


9) Run the app

python app.py


# Find the process ID

lsof -i :5000


# Kill the process (replace PID with actual number)

kill PID


# killing in the terminal where its running

press ctrl + c in the terminal



// Deactive the Virtual environment

deactivate


# Install dependencies

pip freeze > requirements.txt

pip install -r requirements.txt




----------------------------------------------above process after running virtual venv-------------------------------------------------------------


# Install package

pip install package-name


# Save to requirements.txt

pip freeze > requirements.txt

Comments

Popular posts from this blog

VERTICAL SCALING 💋

CyberSecurity

The Journey of Data — "Frontend → Backend → Database → Frontend"