Looking to enhance your Django skills with a practical project? This blog post walks you through how to build and run a Currency Converter Web App using Python and Django, a web application that fetches real-time exchange rates and converts currencies dynamically. Whether you’re a beginner or an intermediate developer, this guide will help you understand Django project structure, API integration, and custom management commands all while working on a real-world app.
Project Overview
The Currency Converter app is a Django-based web application that allows users to convert one currency to another in real-time. It fetches current exchange rates from an external API and updates the database with the latest values. You’ll learn:
- How to build Django models to store currency data
- How to write custom management commands to fetch exchange rates from an API
- How to structure a Django project with virtual environments and best practicesHow to run and test your Django project locally
This is a great hands-on project for beginners and enthusiasts looking to improve their Python and Django skills.
Key Features
- Real-time currency conversion using an external API
- Django-based backend for seamless data handling
- Simple, responsive UI for easy user interaction
- Automated rate updates via custom management command
- SQLite database for storing currency data
Technologies Used
- Python (Backend Logic)
- Django (Web Framework)
- HTML/CSS/JavaScript (Frontend)
- ExchangeRate-API (Real-time currency data)
- SQLite (Database)
Installation & Setup Guide
Follow the steps below to get your Currency Converter app up and running.
Step 1: Activate the Virtual Environment:
Before activation, ensure you’re in the same directory as your `venv` folder:
“`
CurrencyConverter/
└── currency_converter/
└── venv/
“`
Activate the virtual environment using:
venv\Scripts\activate
Step 2: Navigate to Your Django App Directory:
Once the virtual environment is activated, move to the directory containing your `manage.py` file:
“`
currency_converter/
└── converter/
└── currency_converter/
└── db.sqlite3
└── manage.py
“`
Now run the Django server:
python manage.py runserver
Step 3: Open Your App in the Browser:
After running the server, open your browser and navigate to
http://127.0.0.1:8000/
You should see your Django Currency Converter app running! 🎉
Updating Currency Rates Automatically
The project uses a custom Django management command to fetch real-time currency data.
File Path:
“`
converter/
└── management/
└── commands/
└── __init__.py
└── update_rates.py
“`
Get an API Key:
Visit (https://v6.exchangerate-api.com) and sign up to get a free API key. Then insert it into the `update_rates.py` file.
Run the Update Command:
After inserting your API key, run the following command to update the exchange rates:
python manage.py update_rates
Once updated, restart your server to see the latest rates in action.
Troubleshooting
Problem: Can’t activate virtual environment?
Create a new virtual environment
python -m venv venv
Make sure the required libraries inside the `requirements.txt` are installed inside your virtual environment. You can install everything at a go using:
pip install -r requirements.txt
If you are using a Python environment, then make sure all necessary libraries in `requirements.txt` are installed globally.
Download Source Code:
Final Thoughts
Building a currency converter in Django is more than just a project; it’s a stepping stone to mastering API integration, custom commands, and best development practices in Django. Now that your app is running, try adding more features like currency history, multi-language support, or styling with Bootstrap.
Happy coding! 💻🚀
Disclaimer
Sengideons.com does not host any files on its servers. All point to content hosted on third-party websites. Sengideons.com does not accept responsibility for content hosted on third-party websites and does not have any involvement in the same.