Testing of django's create, read, updated, and delete using html templates with postgresql.
- Clone this repository by running
git clone https://github.com/khianvictorycalderon/django-crud-postgresql.git - Generate a safe key using this command in your python interpreter or cmd:
from django.core.management.utils import get_random_secret_key print(get_random_secret_key())
- Create an
.envfile that contains (paste the generated key inDJANGO_SECRET_KEY):Change the allowed credentials depending on where you want your project to be tested.DJANGO_ENV=development DJANGO_SECRET_KEY=your-django-secret-key DEBUG=True ALLOWED_HOSTS=127.0.0.1, localhost DB_NAME=your-db-name DB_USER=your-postgresql-user-name DB_PASSWORD=your-db-password DB_HOST=your-db-host-usually-localhost DB_PORT=your-db-port
- Run the following command for database migration:
python manage.py makemigrationsorpy manage.py makemigrationspython manage.py migrateorpy manage.py migrate
- To run the server, run
py manage.py runserverorpython manage.py runserverChange thepy manage.py runserver 7000 python manage.py runserver 7000
7000if the port is used already or don't have permission for that port. - To create another app, just run
python manage.py startapp <app-name>orpy manage.py startapp <app-name>, example:py manage.py startapp myapp
Install the following first (globally) if you haven't installed it yet:
pip install django psycopg[binary]
