A Haven for Thoughtful Musings
Welcome to Vichar Sagar, a digital haven where ideas flow freely and thoughts find their expression. Inspired by the inquisitive and philosophical spirit of Taarak Mehta from the beloved Indian sitcom, this blog is a testament to the power of intellectual discourse and the beauty of human contemplation.
Just as Taarak Mehta brought laughter and wisdom into the lives of millions, Vichar Sagar aims to spark curiosity, ignite conversations, and foster a deeper understanding of the world around us. Here, you'll find a diverse range of articles exploring topics from philosophy and literature to current affairs and personal reflections.
Join us on this intellectual journey as we delve into the depths of human thought, challenge conventional wisdom, and celebrate the power of ideas. Whether you're a seasoned thinker or just beginning to explore the world of philosophy, Vichar Sagar offers a space for everyone to share their perspectives and connect with like-minded individuals.
Taarak Mehta, the man behind Vichar Sagar, is a passionate writer and thinker deeply influenced by the iconic character from the popular Indian sitcom. With a keen eye for detail and a love for intellectual pursuits, Taarak Mehta brings his unique perspective to the blog, offering insightful commentary and thought-provoking discussions.
Let's embark on this intellectual adventure together!
- Create Virtual Environment
python -m venv .venv
- install
Django
python -m pip install Django
- create a new django project
django-admin startproject mysite
- Setup static and media folders to store static files and assets
import os
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.1/howto/static-files/
STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
MEDIA_URL = 'media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
- steup templates folder
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')], # change this line
'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',
],
},
},
]
- Setup templates
config
- config
- templates
- - base.html
// base.html
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
{% block title %} Vichar Sagar {% endblock %}
</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
serve this template using views and url
# config/urls.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path("", views.hello, name="hello") # here...
]
# config/views.py
from django.http import HttpResponse
from django.shortcuts import render
def hello(request):
return render(request, 'base.html')
- Create a new App
python manage.py startapp app
register the app in the projects settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'vicharsagar', # like so
'tailwind',
'theme'
]
- install
Pillow
package to supportImageField()
in the models
python -m pip install Pillow
- provide
npm.cmd
installation path
TAILWIND_APP_NAME = 'theme'
INTERNAL_IPS = ['127.0.0.1']
NPM_BIN_PATH = "D:/rehan-dev-stuff/node-installation/npm.cmd"
- Install
django-tailwind
package using pip, we’ll be installing another side package along side for hot reload.
python -m pip install 'django-tailwind[reload]'
- include tailwind in the
INSTALLED_APPS
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'vicharsagar',
'tailwind'
]
- run command to initialize tailwind and install the tailwind npm package
python manage.py tailwind init
// output
[1/1] app_name (theme):
Tailwind application 'theme' has been successfully created. Please add 'theme' to INSTALLED_APPS in settings.py, then run the following command to install Tailwind CSS dependencies: `python manage.py tailwind install`
- include the generated
theme
app inINSTALLED_APPS
insettings.py
and run the below command
python manage.py tailwind install
- start tailwind reload mode
python manage.py tailwind start
Deploying a Django app on Vercel requires some configuration because Vercel is primarily designed for frontend frameworks like Next.js, but it can also handle backend applications. To deploy a Django app on Vercel, you’ll use Vercel's serverless functions to serve the app and the ASGI interface, which allows for Django to be deployed in a serverless environment.
Here’s a step-by-step guide:
If you don’t have a Django project, you can create one:
django-admin startproject myproject
cd myproject
Make sure your project uses Django 3.1 or higher, which supports ASGI out of the box. You will also need ASGI and uvicorn for handling the serverless environment.
Install the required dependencies in your requirements.txt
file:
asgiref==3.2.10
Django==3.1.7
uvicorn==0.13.4
If you don't have requirements.txt
, you can generate it:
pip freeze > requirements.txt
Modify myproject/asgi.py
to ensure it's compatible with Vercel’s serverless functions.
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
application = get_asgi_application()
This file will help Vercel understand how to deploy your Django app. In the root of your project directory, create a vercel.json
file.
{
"version": 2,
"builds": [
{
"src": "myproject/asgi.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "myproject/asgi.py"
}
]
}
Create a api/
directory in your project root and move your Django app inside it. The asgi.py
file will be used to serve your app as a serverless function.
Project structure should look like this:
/myproject
/myproject
__init__.py
asgi.py
settings.py
urls.py
wsgi.py
/requirements.txt
/vercel.json
Since Vercel is optimized for static files, you need to configure Django to collect static files before deployment.
In your settings.py
, configure static files and add whitenoise
for serving them in production:
# settings.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
# Add WhiteNoise to middleware to serve static files
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware', # WhiteNoise added here
...
]
# Tell Django to use the staticfiles storage with WhiteNoise
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
Run the following command to collect static files:
python manage.py collectstatic
To deploy your app, install the Vercel CLI:
npm i -g vercel
If you don't already have a Vercel account, create one. Then log in to Vercel:
vercel login
In your project directory, run:
vercel
The command will prompt you to select some options like project name and whether you want to link it to a Git repository.
Once the process is done, your Django app will be deployed on Vercel.
After deployment, you will need to configure environment variables (such as DATABASE_URL
, SECRET_KEY
, etc.) for your Django app in the Vercel dashboard.
To do this:
- Go to your Vercel project dashboard.
- Click on Settings.
- Scroll down to Environment Variables and add any variables your app requires (like your
SECRET_KEY
and database connection).
Since Vercel deployments are stateless, you’ll need to use an external database (e.g., PostgreSQL, MongoDB, etc.) for storing data. You can use services like Heroku Postgres, AWS RDS, MongoDB Atlas, or any other cloud-based database provider.
- Add your external database URL to your
settings.py
:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'your_db_name',
'USER': 'your_db_user',
'PASSWORD': 'your_db_password',
'HOST': 'your_db_host',
'PORT': 'your_db_port',
}
}
- Run migrations:
python manage.py migrate
After deployment, test the app by visiting the Vercel-provided URL. Your Django app should now be live and running on Vercel.
- Set up Django with ASGI and Vercel.
- Use Vercel’s serverless functions and configure the app with a
vercel.json
. - Ensure static files are handled by WhiteNoise and configure the Django app.
- Deploy the app using Vercel CLI.
- Set up environment variables and an external database.
This will deploy your Django app on Vercel, leveraging serverless functions to serve your app.