Install the following prerequisites:
From the root directory run:
python -m venv env
From the root directory run:
On macOS:
source env/bin/activate
On Windows:
env\scripts\activate
From the root directory run:
pip install -r requirements.txt
With PostgreSQL up and running, in a new Terminal window run:
dropdb --if-exists django_polls
Start psql, which is a terminal-based front-end to PostgreSQL, by running the command:
psql postgres
Create a new PostgreSQL database:
CREATE DATABASE django_polls;
Create a new database admin user:
CREATE USER yourusername WITH SUPERUSER PASSWORD 'yourpassword';
To quit psql, run:
\q
Setup your database by editing .env
config file. Replace yourusername
by your postgresql username and
yourpassword
by your postgresql password.
From the root directory run:
python manage.py makemigrations
python manage.py migrate
From the root directory run:
python manage.py createsuperuser
When prompted, enter a username, email, and password.
From the root directory run:
python manage.py runserver
- Docs URL: http://127.0.0.1:8000/api/docs/
- UI Docs URL: http://127.0.0.1:8000/api/docs/ui/
- No base URL (http://127.0.0.1:8000/ raises an Http404 Error)
Add data through Django Admin.
- Go to http://127.0.0.1:8000/admin/ to access the Django Admin interface and sign in using the admin credentials.
- Or add data through the API while by sending a POST request to http://127.0.0.1:8000/api/polls/. It requires an admin account. So you should send a request with login credentials.