Giter VIP home page Giter VIP logo

pemantauan-hidroponik-api's Introduction

Pemantauan Hidroponik API

Menghubungkan ke database

Pada file /api/settings.py, tambahkan informasi database ke variabel DATABASE

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': os.getenv('POSTGRES_DB'),
        'USER': os.getenv('POSTGRES_USER'),
        'PASSWORD': os.getenv('POSTGRES_PASSWORD'),
        'HOST': os.getenv('POSTGRES_HOST'),
        'PORT': os.getenv('POSTGRES_PORT'),
    }
}

Informasi database didefinisikan di dalam file /env berikut.

POSTGRES_DB=
POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_HOST=
POSTGRES_PORT=

Untuk memastikan database sudah terhubung, jalankan command

python manage.py dbshell

nanti tampilannya seperti ini (contoh ada warning):

psql (15.2)
WARNING: Console code page (437) differs from Windows code page (1252)
         8-bit characters might not work correctly. See psql reference
         page "Notes for Windows users" for details.
Type "help" for help.

pemantauan-hidroponik=# \q

Jika belum, pastikan hal-hal berikut sudah terpenuhi:

  • psycopg2-binary sudah ter-install dengan pip install psycopg2-binary
  • psql sudah terdefinisikan di path variable

Cara menggunakan .env

  1. Install library python-dotenv

    pip install python-dotenv
  2. Pada file yang membutuhkan variabel env, tambahkan baris kode berikut

    import os
    from dotenv import load_dotenv
    
    load_dotenv()
  3. Buat file .env dan variabelnya

  4. Cara menggunakan variabel env, dapat merujuk ke sub-chapter Menghubungkan ke database

pemantauan-hidroponik-api's People

Contributors

rosaamalia avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.