This application shows us the possibility of VUE JS interacting with our Django server via the API.
A system has been prepared to check the weather. The main idea:
- Django API Server.
- use API of https://openweathermap.org/api to get new information abot weather of some city.
- save data in database.
- Django REST Framework help us to give information to our Vue JS app.
- Vue JS.
- the user can write the name of city and get information from our Django Api Server.
Interesting points about API of openweather:
- First we need to get parameters such as lon and lat, and only then we search for temperature of a city using them. Therefore, I have prepared a function that makes 2 API requests to search for parameters (lon / lat) of city on request and to search for the weather of the area.
- We get a JSON response with data in Kelvin, so we need to translate it to Celsius.
An interesting problem with requests from VUE JS - Axios to our Django LOCALHOST server. Returns an error when making requests to the local server:
- from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
The solution to this problem:
The main idea is:
pip install django-cors-headers
After installing it, you have to make some edits to your django settings.py
INSTALLED_APPS = ( ... 'corsheaders', ... )
MIDDLEWARE_CLASSES = ( ... 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', ... )
CORS_ORIGIN_ALLOW_ALL = True
DATABASES:
MySQL
optional - PostgreSQL
-
➡️ Check out my website. You can find a detailed description of the projects
-
➡️ Сommercial project. Flask project. Foreign language teacher website. - See on-line website.
-
➡️ Сommercial project. Django project. Online School with personal classrooms of students and teachers. - See online website.
-
➡️ Сommercial project. Django project. For goverment school № 205. - See on-line website.
-
➡️ Django project Mobile shop, education purpose. Working on it