Skip to content

Backend

pradumangoyal edited this page Aug 16, 2019 · 2 revisions

Technical Stack

Python, Django, Django Rest Framework, Pandas, Numpy

Flow of the app

The following image clearly shows the structure of the API endpoints and how they are used by various views on the frontend.

Flow of the app

The various data, numbers are computed at the backend using Python and Pandas at the backend.

Setting up

  1. Clone the Repository

    $ git clone https://github.com/EnsemblGSOC/ecircdb-backend.git ecircdb-backend
    $ cd ecircdb-backend
  2. Make virtual environment setup

    $ pip install virtualenv
    $ virtualenv -p python3 <env_name>

    The aim is to create an independent python3 environment so that the project's dependencies and their version doesn't mix with the local ones ensuring a smooth flow of the app.

  3. Activate your environment

    $ source <env_name>/bin/activate
  4. Install libmysqlclient

    For example on Debian/Ubuntu you must install the package:

    sudo apt-get install libmysqlclient-dev

    For recent versions of debian/ubuntu (as of 2018) it is:

    sudo apt install default-libmysqlclient-dev

    The step is important to install the pip dependency mysqlclient==1.4.2.post1. It requires certain binary files on the host, to connect MySQL database with the Django framework.

  5. Install requirements

    $ pip install -r requirement.txt

    Install various pip packages required in the app from the given file. It's always important to update the file using pip freeze > requirement.txt with the active environment whenever there is a change in the packages or their version.

  6. Create a MySQL user and database normally, remember the name of the database and credentials for the user. Do not create any table structure in your newly created database, all those things should be handled via Django ORM.

  7. Configure the .env file for the project, you can clone the available .env.stencil file to checkout the format for .env file

    $ cp .env.stencil .env

    The file contains the simple configurables, which are used at various places by Django. For ex the credentials to connect with the MySQL server.

  8. Fill out the database name, user, password in the .env file, you can specify the host and port for the database optionally.

  9. Migrate Files

    $ python manage.py makemigrations
    $ python manage.py migrate

    This is the step where the Django ORM does its work. It creates the database schema according to the model structure we defined.

  10. Create a superuser to control the admin panel

    $ python manage.py createsuperuser
  11. Start the server

    $ python manage.py runserver
  12. Visit localhost:8000/control and login using the account created in above step. This is the admin panel from where data can be added, deleted or modified.

  13. Check other urls from the list at localhost:8000/api/

Clone this wiki locally