$ git clone https://github.com/ixdlabs/django-api-template
- Go to
Project Structure > Project
and set the correct SDK. (Create a venv/conda environment) - In
Project Structure > Modules
selectdjango-api-template
and set its name to correct project name. - Go to
Edit Configurations
and AddDjango Server
configuration. SelectUse SDK of Module
as the interpreter.
Use venv
, conda
or a similar virtual environment to install the dependencies.
Use the following command to create the new environment.
$ python -m venv .venv
$ source .venv/bin/activate
Do not follow this if you are using
venv
(Previous section) or a similar virtual environment.
Install Miniconda to create a new virtual environment for project dependencies. Then use the following command to create the new environment. You may need to restart the terminal/command prompt to properly activate the new environment.
$ conda create -n example python=3.10
$ conda activate example
After the environment is created and activated, install the necessary dependencies using the requirements.txt file.
$ pip install -r requirements.txt
Check if following command prints the available command. If the installation is successful, this should not cause an error.
$ python manage.py
$ pre-commit install
Developers do not need to follow this section. This is only for production deployment/testing as is in production. The default configuration is for
sqlite3
database.
Install postgres and setup it according to your OS instructions. Use following
command to login to the psql
shell.
$ psql -U postgres
Then enter below commands.
CREATE ROLE db_user WITH LOGIN PASSWORD 'password';
CREATE
DATABASE example_db;
GRANT ALL PRIVILEGES ON DATABASE
example_db TO db_user;
\q
Then login to psql
as db_user
and check if the setup is done correctly. Password should be password
.
psql -U db_user example_db
- Install postgresql in the local machine and setup correctly. Do not change default
port or other settings. Give a password to
postgres
user when asked. - Login to
pgAdmin
using the username and password give in the setup process. From theBrowser
panel, selectServer>postgres>Login/Group Roles
and right click and create the role. Givedb_user
as role name and givepassword
as the password. - Then right click
Server>postgres>Databases
and Create new database. Giveexample_db
as the database name and setdb_user
as the owner. - Then try to login to
psql
shell using default port, server, databaseexample_db
anddb_user
user.
First run the database migration and create the necessary tables. Make sure you are in the correct virtual environment. Whenever there is a database model change, you should re-run this.
$ python manage.py migrate
Then create the static files required for the project. You should run this again when you pull from the upstream.
$ python manage.py collectstatic
Then load the fixtures. (Optional) This will load the initial data for the project.
Dumping fixtures can be done as python manage.py dumpdata APP.MODEL > apps/APP/fixtures/APP_MODEL.json
.
$ python manage.py loaddata admin_interface_theme_uswds.json
Finally, create the user account. This will be the default admin user for the system. Give a preferred username and password.
$ python manage.py superuser --username superadmin --password userpassword
# Or to create interactively
$ python manage.py createsuperuser
Afterwards try running the project. The default url for the dashboard is http://127.0.0.1:8000/
$ python manage.py runserver
Set USE_MAILHOG
to True
and run MailHog
to capture outgoing emails.