A simple and efficient URL shortener built with Django, deployed on Google Cloud Run, and using Neon as a database in production.
- Shorten long URLs into concise links
- Redirect users from short links to original URLs
- Simple admin panel for managing URLs
- SQLite for local development and Neon for production database
- Backend: Django 5
- Database: SQLite (local), Neon (production)
- Deployment: Google Cloud Run
- Environment Management: Python dotenv
- Python 3.x installed
- Virtual environment setup
- Clone the repository:
git clone https://github.com/MHamzaImran/url_shortener.git cd url_shortener
- Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
Create a
.env
file and add the following:SECRET_KEY=<your-secret-key> DEBUG=True # Set to False in production DATABASE_URL=<your-neon-database-url> PORT=8080
- Apply migrations:
python manage.py migrate
- Run the server:
python manage.py runserver
- Build and push Docker image:
gcloud builds submit --tag gcr.io/<your-project-id>/theurlshortener
- Deploy to Cloud Run:
gcloud run deploy theurlshortener --image gcr.io/<your-project-id>/theurlshortener --platform managed --region us-central1 --allow-unauthenticated
- SECRET_KEY: Never expose your secret key in public repositories.
- DEBUG Mode: Set
DEBUG=False
in production to prevent security vulnerabilities. - ALLOWED_HOSTS: Restrict it to your domain in production.
This project is open-source under the MIT License.
For any queries, feel free to reach out to:
Muhammad Hamza Imran
LinkedIn | GitHub | Portfolio