A simple URL shortener built with Flask and SQLite. This project allows users to create shortened URLs and track their usage statistics.
- Shorten long URLs to manageable lengths
- Track click statistics for each shortened URL
- View creation date and total clicks for each URL
- Clean and responsive user interface
- SQLite database for persistent storage
- Clone the repository:
git clone https://github.com/maty7253/py-url-shortener.git
cd url-shortener
- Create a virtual environment and activate it:
python -m venv venv
source venv/bin/activate # On Windows, use: venv\Scripts\activate
- Install the required packages:
pip install -r requirements.txt
- Start the application:
python app.py
- Open your web browser and navigate to
http://localhost:5000
- Enter a URL to shorten it
- View statistics at
http://localhost:5000/stats
url-shortener/
├── app.py # Main application file
├── requirements.txt # Project dependencies
├── urls.db # SQLite database (created automatically)
└── templates/ # HTML templates
├── index.html # Home page template
└── stats.html # Statistics page template
- Fork the repository
- Create a new branch (
git checkout -b feature/improvement
) - Make your changes
- Commit your changes (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature/improvement
) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
This URL shortener project includes:
-
A Flask web application (
app.py
) that handles:- URL shortening
- Redirect functionality
- Click tracking
- Statistics viewing
-
Two HTML templates with a clean, responsive design using Tailwind CSS:
index.html
for the main URL shortening interfacestats.html
for viewing URL statistics
-
A SQLite database to store:
- Original URLs
- Short codes
- Creation timestamps
- Click counts
-
A comprehensive README.md file for GitHub
To get started with this project:
- Create a new GitHub repository
- Copy these files into your repository
- Follow the installation instructions in the README
- Push the code to GitHub
The application features:
- Clean and intuitive user interface
- Input validation
- Click tracking
- Statistics page
- Responsive design
- Secure random short code generation
- Automatic database initialization
You can extend this project by adding features like:
- User authentication
- Custom short codes
- API endpoints
- QR code generation
- Link expiration
- Analytics dashboard