After weeks of focused development, troubleshooting, and iteration, I’m proud to share that my Django-based portfolio project — MiPortafolioDjango — is now fully deployed and live in production!
🔗 Check it out here: nicolasandrescl.pythonanywhere.com
This deployment involved much more than pushing code — it was a comprehensive hands-on learning experience covering configuration management, static and media file handling, security, and debugging in a real-world production environment.
⚙️ Key Improvements and Configurations
I. Django Configuration (settings.py & wsgi.py)
🔐 Secure Key Management with python-decouple
Sensitive data like SECRET_KEY and EMAIL_HOST_PASSWORD were externalized using the python-decouple package.
A .env file was created at the root of the project to store these secrets securely.
The wsgi.py file was modified to explicitly load environment variables using pathlib.Path and config() from decouple.
📁 Static Files Configuration
Set STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') in settings.py.
Ran python manage.py collectstatic to collect and serve static files on the server.
🖼 Media Files Configuration
Configured MEDIA_URL and MEDIA_ROOT to handle uploaded files using Django’s ImageField.
This enabled uploaded images to be visible through the admin and rendered on the frontend.
🌍 Production Settings
ALLOWED_HOSTS was updated to include nicolasandrescl.pythonanywhere.com.
Set DEBUG = False for security in production.
Confirmed that portfolio_project/wsgi.py contains necessary .env loading logic to work independently of PythonAnywhere’s default.
II. Server Setup on PythonAnywhere
✅ Repository Sync: Cleaned and re-pushed the latest repo to GitHub, then pulled it into PythonAnywhere.
🐍 Virtual Environment: Activated the virtualenv properly using workon MiPortafolioDjango_env.
🛠 Migrations & Superuser: Ran migrate and created a superuser for admin access.
🗂 Static & Media Files Web Config: Added /static/ and /media/ mappings in the Web > Static Files section.
🔁 App Reloads: Performed necessary web app reloads after every major change.
🧠 Advanced Debugging: Inspected error.log and server.log for resolving tricky deployment issues.
🐛 Critical Fixes Before Production Launch
🔄 GitHub URL Redirection Bug
Fixed a bug where all project cards linked to the same (wrong) GitHub repo.
Root cause: hardcoded URLs in the HTML template.
Solution: replaced with {{ project.github_link }} to dynamically fetch the correct link.
🖼 Project Image Display Issues
Solved the problem where project images didn’t render on the frontend.
Verified correct use of ImageField and ensured MEDIA_URL and MEDIA_ROOT were properly configured.
Now images uploaded via Django Admin appear seamlessly on the site.
🧩 Conclusion
This deployment marks a significant step forward in my journey as a backend developer. The process not only strengthened my understanding of Django and server-side deployment, but also gave me real DevOps exposure by working directly with environment variables, file systems, and web server configurations.
🔍 Every issue resolved and each configuration tweaked is now a new skill in my toolkit.
Check it out, and feel free to leave feedback!
Top comments (0)