This is a blogging service API developed using Python/Django/Django Rest Framework(DRF)
This service provides basic blogging functionality such as posts, likes, and followers. But all of these functions are only available after authentication, so this API implements registration with email confirmation as well as login/logout. Also, each user has his own profile, which he can edit, for example, add contacts(links to social networks), change avatar, change status, etc.
In this project, I am using the Google Drive API to save user avatar images. I did this in order to be able to run a project on a hosting with an ephemeral file system. Thus, you can also run this code on a hosting with an ephemeral filesystem without worrying about files integrity.
- Clone this repository
- Create a folder named "media" in the root folder of the project
- Create a .env file with the following content
# Common Django settings
SECRET_KEY="" # You can enter any random string here(this is used to provide cryptographic signing)
DEBUG=1 # 1-True, 0-False
ALLOWED_HOSTS="localhost 127.0.0.1 [::1]"
# CORS configuration
# front-end server address(address from which requests will be sent to the api server)
CORS_ALLOWED_ORIGINS="localhost:3000 [::1]"
CORS_ORIGIN_WHITELIST="localhost:3000 [::1]"
# JWT
SIGNING_KEY="" # This key is used to provide cryptographic signatures for JWT tokens(any random string)
# Send mail server configuration
EMAIL_HOST="" # mail server address(e.g smtp.gmail.com)
EMAIL_HOST_USER="" # mail server account(e.g [email protected])
EMAIL_HOST_PASSWORD="" # mail server password
EMAIL_USE_TLS=1 # whether to use TLS encryption connection(1-True, 0-False)
EMAIL_PORT= # mail server port
# Database configuration
# If you will be using docker to start the server use this configuration
DB_ENGINE="django.db.backends.postgresql" # engine
DB_DATABASE="django_drf_dev_db" # database name used in the database
DB_USER="django_drf_dev" # database user name
DB_PASSWORD="django_drf_dev" # database password
DB_HOST="db" # database address
DB_PORT=5432 # database access port
- Then you need to set up Google Drive
- Install python, pip and pipenv if you haven't already
- Create a virtual environment using the following command
> pipenv shell
- Install all dependencies
> pipenv install
- Enter the following command to run the migrations
> pipenv run python manage.py migrate
- Create a superuser if you need one
> pipenv run python manage.py createsuperuser
Then start the server
> pipenv run python manage.py runserver
After starting the development server, the provided interface is located at http://localhost:8000/api/v1, the admin panel address is http://localhost:8000/admin
- Create new project on Google Cloud Platform
- Enable Google Drive API for this project
- Create credentials of type "service account"
- Create a new private key with JSON key type and download it
- Rename the key file to "google_drive_api.json" and move it to the config/ folder
If you want to start the server in docker follow these steps
- Complete steps 1-4 from "How to Use"
- Install docker and docker-compose if you haven't already
- Build a new image and spin up two containers(django server and postgres)
> docker-compose up -d --build
- Run the migrations using the following command
> docker-compose exec web python manage.py migrate
- Create a superuser if you need one
> docker-compose exec web python manage.py createsuperuser
The provided interface is located at http://localhost:8000/api/v1, the admin panel address is http://localhost:8000/admin
To run tests, enter the following command
> pipenv run python manage.py test
This project is licensed under the MIT License - see the LICENSE file for details