https://github.com/coderooz/flask-url-shortener
This is a simple URL shortener application built with Flask and Python. It allows users to shorten long URLs and then redirect to the original URLs using a short key.
https://github.com/coderooz/flask-url-shortener
flask python url-shortener
Last synced: 8 months ago
JSON representation
This is a simple URL shortener application built with Flask and Python. It allows users to shorten long URLs and then redirect to the original URLs using a short key.
- Host: GitHub
- URL: https://github.com/coderooz/flask-url-shortener
- Owner: coderooz
- License: mit
- Created: 2024-08-25T03:35:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-25T03:45:06.000Z (over 1 year ago)
- Last Synced: 2025-03-29T13:51:45.366Z (12 months ago)
- Topics: flask, python, url-shortener
- Language: Python
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Flask URL Shortener
This is a simple URL shortener application built with Flask and Python. It allows users to shorten long URLs and then redirect to the original URLs using a short key.
## Features
- Shorten URLs and redirect to the original URL using a short key.
- Display the shortened URL on the homepage.
## Prerequisites
- Python 3.x
- Flask (installable via pip)
## Setup
1. **Clone the repository**
```bash
git clone https://github.com/coderooz/flask-url-shortener.git
cd flask-url-shortener
```
2. **Create and activate a virtual environment**
```bash
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\Activate.ps1
```
3. **Install the required packages**
```bash
pip install flask
```
4. **Create the template file**
Create a file named `index.html` in a folder named `templates` in the same directory as `app.py` with the following content:
```html
URL Shortener
URL Shortener
Enter URL:
{% if short_url %}
Short URL: {{ short_url }}
{% endif %}
```
## Running the Application
1. **Run the Flask application**
```bash
python app.py
```
2. **Open your web browser and go to** `http://127.0.0.1:5000/` or `http://localhost:5000/`
You should see the URL shortener form. Enter a URL and click "Shorten" to get a shortened URL.
## How It Works
- **Homepage (`/`)**: Displays a form where users can enter a URL to shorten. The shortened URL will be displayed on the same page.
- **Shorten URL (`/shorten`)**: Accepts a POST request with the original URL, generates a short key, and stores the mapping in memory.
- **Redirect (`/`)**: Redirects to the original URL based on the short key.
## Note
This application uses in-memory storage for URL mappings, which means that all URLs will be lost if the server is restarted. For production use, consider integrating a persistent database.
## Future Integrations
- **Database**
- **Added UI Interface**
- **User Login**
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Author
**Ranit Saha**