- Python3
- Django4
- PostgreSQL - As production and dev DB
- ReactJS - Froent-end UI elements
- DRF (Django Rest Framework) - Using it to follow the REST methodology
- Nginx - As proxy server
- Docker - project deploying (dev and prod deploying versions)
The WeatherApp index page represented by ReactJS elements. First what you seee - select box with countries. To see how WeatherApp is giving weather info just do steps:
- Choose country you want from first select
- After this you'll see select with cities - choose city you want
- When city choosed, the result with weather info will displayed down with grid displaying system
Based on them i build files that contains only necessary info for app, files placed in weatherapp/static/weatherapp/files/json/:
- countries_cities.json
- countries.json
- Restful
- Client-server
- Stateless No request's data storage in DB or any other storage
- Cacheability Caching all server's responses for save time when client asks same info. Represented in project by Cache class.
- Uniform interface Giving neccessary info about content types and another actions that client can do with the asked resourse by using Django REST Framework.
- Business logic in Classes All business logic and necessary functionality represented in Classes. Using that architecture make able easily expanding existing functions by inheritance BaseAPI Abstract class and definition methods for new API calls. It also easier to auto-test it
That also make able to make your views look like short calling the object's methods https://github.com/AlexDolls/WeatherAPIApp/blob/master/weatherapp/views.py
@api_view(['GET'])
@parser_classes([JSONParser])
def get_current_weather(request):
city = request.GET.get("city", "Kiev")
country_code = request.GET.get("countrycode", "")
weather_api_object = CurrentWeather(GeoCording(city, country_code))
weather_info = weather_api_object.send()
return Response(weather_info)
Install Docker Engine and Docker Compose on your PC.
-
Rename .env.dev-sample to .env.dev.
-
Update the environment variables in the docker-compose.yml and .env.dev files.
-
Build the images and run the containers:
$ docker-compose up -d --build
-
Don't forget to create superuser (needs to get access to admin panel)
$ docker-compose exec web python3 manage.py createsuperuser
Test it out at http://localhost:8000(http://127.0.0.1:8000).
Uses daphne + nginx.-
Rename .env.prod-sample to .env.prod and .env.prod.db-sample to .env.prod.db. Update the environment variables as you need.
-
Build the images and run the containers:
$ docker-compose -f docker-compose.prod.yml up -d --build
-
Make migartions to DB
$ docker-compose -f docker-compose.prod.yml exec web python3 manage.py makemigrations $ docker-compose -f docker-compose.prod.yml exec web python3 manage.py migrate
-
Collect staticfiles
$ docker-compose -f docker-compose.prod.yml exec web python3 manage.py collectstatic
-
Don't forget to create superuser (needs to get access to admin panel)
$ docker-compose exec web python3 manage.py createsuperuser
Test it out at http://localhost:1337(http://127.0.0.1:1337). To apply changes, the image must be re-built.