A Guide: A Django-REST-React-Redux Blueprint (Part 1)
Intro + Python Environment
I.Preface
This guide intends to show the steps to create a minimal Full Stack with Django, the Django-REST-Framework (DRF), ReactJS and Redux. This means (for me), that the project is set up for development and deployment with nginx, gunicorn and Docker on AWS’s Elastic Container Service (ECS). There are multiple ways to accomplish this task, mine may not be the best practice at every step, but it worked out for me in my project. So if you see any mistakes or superior solutions, do not hesitate to inform me about it. This guide is a step by step process of me, recap my knowledge, which originated through reading and testing others guides and working on an early phase product. It might be a long journey, but it will fulfill my wish to have all the things, that worked for me at one place (you don’t wanna see my bookmark list).
If you are only interested in cloning my blueprint, see here or you want something more profound, see here.
Disclaimer: All tasks are done on a mac (sorry windows users).
II. Content
- Python Environment
- Django/Django-REST-Framework
- Webpack, React
- Redux
- Docker and Deployment on AWS
- Integration of Bootstrap 4 with react-bootstrap
Python Environment:
The first step is a clean Python project setup. For me this includes:
- A Python version management.
- A virtual environment tool (mandatory).
- An IDE, linting, debugging, running etc.
1. Multiple options exists to manage our Python versions, I recommend pyenv. It has a simple interface and is easy to setup. To setup pyenv I recommend brew (there are other ways):
$ brew update
$ brew install pyenv
Edit thebash profile $ sudo nano ~/.bash_profile
and add the following line at the bottom and restart the terminal:
eval "$(pyenv init -)"
Install Python version 3.6.0(or higher, but be careful with taking the newest one, they might be still active issues with Django):
$ pyenv install 3.6.0
(for other version see pyenv install --list)
After installing a Python version you can list your versions with pyenv versions
. Now create a new project, navigate to it and set the Python version with
$ pyenv local 3.6.0
This will write a .python-version
file, for which pyenv is looking for. Now, if you have set a different global Python version, you can try out typing python
inside and outside our project. The outcome will differ if our pyenv setup was correct.
2. After we set the Python version for our project with pyenv, we can now create the virtual environment. For this mandatory task I chose the tool virtualenv. For installing virtualenv use
$ [sudo] pip install virtualenv
create the virtual environment inside our project (so pyenv will use the correct python version) and don’t add the virtual environment to git.
$ virtualenv --python=python virtual-env-blueprint
3. Install an IDE, I recommend PyCharm and set the project Python interpreter to our fresh virtual environment
This will tell PyCharm to open every terminal session within our virtual environment
This completes the Python Environment for this guide. If our setup was successful our projectfolder
should have these contents
.
├── .git
├── .python-version
└── virtual-env-blueprint
If this setup doesn’t fulfill your demands, you can read further on this topic
- The definitive guide to setup my Python workspace
- How to manage multiple Python versions and virtual environments
After finishing our Python Environment we will setup Django in the next Part (Link).