A React and Django web-app that display weather based on the city entered by the user.
cd
into it and run following commands:
# Create a virtual environment for the backend
virtualenv env
# Activate the virtual environment
source env/bin/activate
# Install the packages
pip install -r requirements.txt
# Make build.sh executable
chmod +x build.sh
# Install nodemon gloablly to auto-reload the server when making changes in the files
npm install -g nodemon
# cd into the frontend directory
cd frontend
# Install packages for the React app
npm install
# Use npm-watch to track the changes being made in the React app
npm run watch
Inside the frontend/src/APIKeys
folder, specity your GooglePlaces’ API key and OpenWeatherMap’s API key in the respective files.
Now, open up a new terminal, go inside the repo and run following commands:
source env/bin/activate
cd backend
# To run Django dev server and watch file changes in the app
nodemon --exec python manage.py runserver
frontend
directory:npm start
in the frontend
directory, after installing the node_modules.backend
directory:build.sh
:env
: requirements.txt
:frontend/package.json
, npm-watch module is included as a dev dependency because it will detect changes in the React app (frontend/src
and frontend/public
) and buildapp
will run build.sh
script.build.sh
script runs, it will generate static bundle files from the React app and ./manage.py collectstatic
will collect those static files and store them inside backend/static
frontend/build/root/
whenever needed.frontend/build/static
will be served at /static/
URL, settings for the same are specified in backend/weatherfinder/settings.py
.urls.py
will go to views.py
, which will render index.html
file of React app.index.html
when rendered, will have links to static JS bundle files and they’ll be considered as Django templates and served from there.nodemon --exec python manage.py runserver
will run the development server and every time some changes happen in the Django web-app or its static files, nodemon will re-start the django dev server.Endpoint to Display list of cities based on initials of input
Instruction to setup API keys for Google Places API
Reference: Hybrid app model used to integrate React app with Django