This repo is based on Django React Boilerplate.
- Set the firebase bucket storage to public https://cloud.google.com/storage/docs/access-control/making-data-public. So that other users able to see the images.
-
cd frontend npm install npm run build:dll npm start
Then open web browser and enter URL according to the URL and port as shown in the terminal
-
install Django (make sure using python 3.8)
pip install django
-
sudo apt-get install gcc libpq-dev -y sudo apt-get install python-dev python-pip -y sudo apt-get install python3-dev python3-pip python3-venv python3-wheel -y
-
create environment (Use python 3) and activate the environment
python3 -m venv env source ./env/bin/activate
Make sure the environment always active for executing the below commands
-
install wheel
pip3 install wheel
-
run the below command
make compile_install_requirements
In Windows 10, run
pip-compile requirements.in
and copy paste the terminal output to therequirements.txt
. Repeat fordev-requirements.in
and save it todev-requirements.txt
.Then run
pip install -r requirements.txt pip install -r dev-requirements.txt
-
Inside the
backend
folder, do the following:Create a copy of
awascovid/settings/local.py.example
:
cp awascovid/settings/local.py.example awascovid/settings/local.py
Create a copy of
.env.example
:cp .env.example .env
-
database migration
cd backend/ python3 manage.py makemigrations python3 manage.py migrate
-
In order to run the server on the same network such as a wifi,
python3 ./manage.py runserver 0.0.0.0:8000
-
Set ALLOWED_HOSTS = ['*']
-
In order to delete the backend database, just delete the db.sqlite3 file in the backend folder, and delete the xxxx_initial.py in the modified migrations folder. Then make a Django makemigrations and migrate.
-
Make sure using python > 3.8 from python.org.
Open Powershell in windows 10
Create environment
python -m venv env
.\env\Scripts\activate
keep the environment active
-
Install pip and requirements
pip install -r requirements.txt
pip install -r dev-requirements.txt
-
Inside the
backend
folder, do the following:Create a copy of
awascovid/settings/local.py.example
:
cp awascovid/settings/local.py.example awascovid/settings/local.py
Create a copy of
.env.example
:cp .env.example .env
-
database migration
cd backend/ python manage.py makemigrations python manage.py migrate
-
In order to run the server on the same network such as a wifi,
python ./manage.py runserver 0.0.0.0:8000
A Django project boilerplate/template with lots of state of the art libraries and tools like:
- React, for building interactive UIs
- django-js-reverse, for generating URLs on JS
- Bootstrap 4, for responsive styling
- Webpack, for bundling static assets
- Celery, for background worker tasks
- WhiteNoise with brotlipy, for efficient static files serving
- prospector and ESLint with pre-commit for automated quality assurance (does not replace proper testing!)
For continuous integration, a CircleCI configuration .circleci/config.yml
is included.
Also, includes a Heroku app.json
and a working Django production.py
settings, enabling easy deployments with 'Deploy to Heroku' button. Those Heroku plugins are included in app.json
:
- PostgreSQL, for DB
- Redis, for Celery
- Sendgrid, for e-mail sending
- Papertrail, for logs and platform errors alerts (must set them manually)
This is a good starting point for modern Python/JavaScript web projects.
- Make sure you have Python 3.8 installed
- Install Django with
pip install django
, to have thedjango-admin
command available. - Open the command line and go to the directory you want to start your project in.
- Start your project using:
django-admin startproject theprojectname --extension py,yml,json --name Procfile,Dockerfile,README.md,.env.example,.gitignore --template=https://github.com/vintasoftware/django-react-boilerplate/archive/boilerplate-release.zip
In the next steps, always remember to replace theprojectname with your project's name
-
Above: don't forget the
--extension
and--name
params! -
Navigate to the project's directory through your command line.
-
Create a new virtualenv with either virtualenvwrapper or only virtualenv:
mkvirtualenv awascovid
orpython -m venv awascovid-venv
.If you're using Python's virtualenv (the latter option), make sure to create the environment with the suggested name, otherwise it will be added to version control.
-
Make sure the virtualenv is activated
workon awascovid
orsource awascovid-venv/bin/activate
. -
Compile the requirements before installation and install them:
make compile_install_requirements
-
Change the first line of README to the name of the project
-
Add an email address to the
ADMINS
settings variable inawascovid/backend/awascovid/settings/base.py
-
Change the
SERVER_EMAIL
to the email address used to send e-mails inawascovid/backend/awascovid/settings/production.py
-
Rename the folder
circleci
to.circleci
with the commandmv circleci .circleci
After completing ALL of the above, remove this Project bootstrap
section from the project README. Then follow Running
below.
- Inside the
backend
folder, do the following: - Create a copy of
awascovid/settings/local.py.example
:
cp awascovid/settings/local.py.example awascovid/settings/local.py
- Create a copy of
.env.example
:cp .env.example .env
- Create the migrations for
users
app:python manage.py makemigrations
- Run the migrations:
python manage.py migrate
- Create the migrations for
users
app:
docker-compose run --rm backend python manage.py makemigrations
- Run the migrations:
docker-compose run --rm backend python manage.py migrate
- Setup editorconfig, prospector and ESLint in the text editor you will use to develop.
- Open a command line window and go to the project's directory.
pip install -r requirements.txt && pip install -r dev-requirements.txt
npm install
npm run start
- Open another command line window.
workon theprojectname
orsource theprojectname/bin/activate
depending on if you are using virtualenvwrapper or just virtualenv.- Go to the
backend
directory. python manage.py runserver
- Open a command line window and go to the project's directory.
docker-compose up -d
To access the logs for each service rundocker-compose logs -f service_name
(either backend, frontend, etc)
- Open a command line window and go to the project's directory
workon theprojectname
orsource theprojectname/bin/activate
depending on if you are using virtualenvwrapper or just virtualenv.python manage.py celery
make test
Will run django tests using --keepdb
and --parallel
. You may pass a path to the desired test module in the make command. E.g.:
make test someapp.tests.test_views
Add the libname to either requirements.in or dev-requirents.in, then either upgrade the libs with make upgrade
or manually compile it and then, install.
pip-compile requirements.in > requirements.txt
or make upgrade
pip install -r requirements.txt
Before you start creating your own apps remove the example:
- Run the command
make clean_examples
in order to clean up the example apps from the front and backend. - Deregister the example app by removing
'exampleapp.apps.ExampleappConfig'
frombackend/awascovid/settings/base.py
. - Adjust
backend/awascovid/urls.py
to point to your newly created Django app and remove the path configuration that redirects to the deleted example app.
This project comes with an app.json
file, which can be used to create an app on Heroku from a GitHub repository.
After setting up the project, you can init a repository and push it on GitHub. If your repository is public, you can use the following button:
If you are in a private repository, access the following link replacing $YOUR_REPOSITORY_LINK$
with your repository link.
https://heroku.com/deploy?template=$YOUR_REPOSITORY_LINK$
Remember to fill the ALLOWED_HOSTS
with the URL of your app, the default on heroku is appname.herokuapp.com
. Replace appname
with your heroku app name.
Sentry is already set up on the project. For production, add SENTRY_DSN
environment variable on Heroku, with your Sentry DSN as the value.
You can test your Sentry configuration by deploying the boilerplate with the sample page and clicking on the corresponding button.
The bin/post_compile
script has a step to push Javascript source maps to Sentry, however some environment variables need to be set on Heroku.
You need to enable Heroku dyno metadata on your Heroku App. Use the following command on Heroku CLI:
heroku labs:enable runtime-dyno-metadata -a <app name>
The environment variables that need to be set are:
SENTRY_ORG
- Name of the Sentry Organization that owns your Sentry Project.SENTRY_PROJECT_NAME
- Name of the Sentry Project.SENTRY_API_KEY
- Sentry API key that needs to be generated on Sentry. You can find or create authentication tokens within Sentry.
After enabling dyno metadata and setting the environment variables, your next Heroku Deploys will create a release on Sentry where the release name is the commit SHA, and it will push the source maps to it.
- Manually with
prospector
andnpm run lint
on project root. - During development with an editor compatible with prospector and ESLint.
- Run
pre-commit install
to enable the hook into your git repo. The hook will run automatically for each commit. - Run
git commit -m "Your message" -n
to skip the hook if you need.
Some settings defaults were decided based on Vinta's experiences. Here's the rationale behind them:
We believe Celery tasks should be idempotent. So for us it's safe to set CELERY_ACKS_LATE = True
to ensure tasks will be re-queued after a worker failure. Check Celery docs on "Should I use retry or acks_late?" for more info.
If you wish to contribute to this project, please first discuss the change you wish to make via an issue.
Check our contributing guide to learn more about our development process and how you can test your changes to the boilerplate.
This project, as other Vinta open-source projects, is used in products of Vinta clients. We are always looking for exciting work, so if you need any commercial support, feel free to get in touch: [email protected]
Copyright (c) 2020 Vinta Serviços e Soluções Tecnológicas Ltda.