Giter Club home page Giter Club logo

django-react-boilerplate's Introduction

DIY Django and React Boilerplate for SaaS

It is a do-it-yourself Django + React Boilerplate for starting your SaaS application. In existing boilerplates for Django+React (or just for Django), there are very often too many features provided (do you really need traffik for MVP?). So before starting, you need to remove a lot of functionality that you don't need or simply don't understand.

I decided to create a simple Django+React boilerplate with step-by-step instructions on how to build it. During building, you can decide what you need or not. And for sure, you learn a lot about Django and React. I hope it will provide a good and quick starting point for creating SaaS applications. I want to create real SaaS applications based on this boilerplate with step-by-step tutorials on how they were created. They will be available on SaaSitive website.

Features (already implemented or planned)

  • Backend with Django Rest Framework
  • Frontend with React
  • Bootstrap for styling
  • Deployment with docker-compose on a single VPS
  • SSL certificate from Let's encrypt
  • PostgreSQL database (not yet configured)
  • Authentication with DRF authtoken and Djoser
  • AWS SES for Email sending (not yet implemented)
  • python-decuple for secrets
  • Payments with Stripe (not yet implemented)
  • Step-by-step instructions on how to deploy and how to update the application

Step-by-step instructions:

  1. Starting SaaS with Django and React (tag v1)
  2. React Routing and Components for Signup and Login (tag v2)
  3. Token Based Authentication with Django Rest Framework and Djoser (tag v3)
  4. React Token Based Authentication to Django REST API Backend (tag v4)
  5. React Authenticated Component (tag v5)
  6. CRUD in Django Rest Framework and React (tag v6)
  7. Docker-Compose for Django and React with Nginx reverse-proxy and Let's encrypt certificate (tag v7)
  8. Django Rest Framework Email Verification (tag v8)
  9. Django Rest Framework Reset Password (tag v9)

More articles coming soon!

Screenshots

django-react-boilerplate's People

Contributors

aplonska avatar pplonski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-react-boilerplate's Issues

Form field validation not working due to typo (400 Bad Request)

In part 4 of the tutorial, the field validation doesn't fire up when we hit send with empty username and password fields.

In the tutorial code, there is a typo in SignupActions.js on line 23.
It says
if (error.resposne) {

instead of
if (error.response) {

Because of this CREATE_USER_ERROR is never set and later on in the tutorial, when connecting to the api, sending the form with empty fields results in a 400 Bad Request response.

Connecting to Postgresql database

Nothing is broken at all, but i went ahead and setup a connection to a persistent postgresql database, and wanted to lay out here what i did in case it's of use to anyone.

It's possible that there are better ways to do the steps below, but it works :)

Plus, feel free to use any of this if there are any additional articles in this great series!

Updates to files

Dockerfile

  1. install postgres client and server by adding before WORKDIR /app:
# Install postgres client so we can access the db directly from command line (see below)
RUN apk add --update --no-cache postgresql-client

and (note, i had to add gcc for compile reasons)

RUN apk update \
    && apk add postgresql-dev gcc python3-dev musl-dev libffi-dev openssl-dev

docker-compose.yml

  1. add this to top of services section, above nginx:
    db:
        image: postgres
        restart: always
        volumes:
            - pgdata:/var/lib/postgresql/data
        environment:
            - POSTGRES_DB=postgres
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=postgres
  1. update volumes section at the bottom:
volumes:
    static_volume: {}
    pgdata: {}
  1. add this to end of service/backend section:
    depends_on:
        - db

settings.py

updates to django's backend/server/server/settings.py file. add this after the default sqlite3 db is set (change name of db/user/pwd as you wish; just make sure to change it to match in the docker-compose.yml file as noted above):

if not DEBUG:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'NAME': 'postgres',
            'USER': 'postgres',
            'PASSWORD': 'postgres',
            'HOST': 'db',
            'PORT': 5432,
        }
    }

requirements.txt

addition to backend/requirements.txt:

psycopg2-binary>=2.8

Note, you'll likely need to comment this line out for locally. ideally we can add a server check so this doesn't get added locally when using sqlite3 default db.

That's it.

Doing those steps, it auto created the volume first time i launched, and the database connected successfully, and the db persists across sessions, even if i rebuild the docker images.

Working w/ the postgres db directly

This is only useful if you can login to your docker server via ssh and work through the command line.
Once logged into the server via ssh, you do:

  1. docker ps to get container id
  2. docker exec -it [container_id_here] sh to get into postgres container as an sh shell
  3. su postgres to change to the user who owns the db situation
  4. psql to take you into psql so you can work with db.

to get out, just type 'exit' a few times.

Conclusion.

I really appreciated this tutorial, one of the most useful and i wanted to help w/ folks interested in persistent db connection.

Dummy certificates key size too small in `init-letsencrypt.sh`

This repo was a huge help, thanks ๐Ÿš€ ๐Ÿ’ฏ

For anyone's reference , I ran into an issue similar to this where the rsa key size argument is too small when generating the dummy certificates to boot up nginx

error:

SSL routines:SSL_CTX_use_certificate:ee key too small

in this command

docker-compose run --rm --entrypoint "\
  openssl req -x509 -nodes -newkey rsa:1024 -days 1\
    -keyout '$path/privkey.pem' \
    -out '$path/fullchain.pem' \
    -subj '/CN=localhost'" certbot

I had to change rsa:1024 to rsa:4096 to get it to work.

Could potentially use the same rsa_key_size variable in the script as well

Not working with aws ec2 instance

working with docker-compose-dev.yml but with another ec2 instance and docker-compose giving error

Certbot failed to authenticate some domains (authenticator: webroot). The Certificate Authority reported these problems:
Domain: mydomain.com
Type: unauthorized
Detail: Invalid response from http://mydomain.com/.well-known/acme-challenge/sklMcsF8-vKNJkzKqo95shFDXqdr7uiaOpWDiGspyrs [13.233.108.169]: "<!doctype html><html lang="en"><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="

Domain: www.mydomain.com
Type: unauthorized
Detail: During secondary validation: Invalid response from http://www.mydomain.com/.well-known/acme-challenge/LH-LaBi42ZGOZAeTHycKAEKN670LF5m-ErwbXYzpeNs [13.233.108.169]: "<!doctype html><html lang="en"><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="

Hint: The Certificate Authority failed to download the temporary challenge files created by Certbot. Ensure that the listed domains serve their content from the provided --webroot-path/-w and that files created there can be downloaded from the internet.

Some challenges have failed.
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

Reloading nginx ...

2021/08/04 06:39:21 [emerg] 31#31: cannot load certificate "/etc/letsencrypt/live/mydomain.com/fullchain.pem": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/letsencrypt/live/mydomain.com/fullchain.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)
nginx: [emerg] cannot load certificate "/etc/letsencrypt/live/mydomain.com/fullchain.pem": BIO_new_file() failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/etc/letsencrypt/live/mydomain.com/fullchain.pem','r') error:2006D080:BIO routines:BIO_new_file:no such file)

Nginx DockerFile update and course completion request

Dear Piotr Pล‚oล„ski

Thank you very much for your tutorials. Undoubtedly, using this structure can create valuable applications.

After cloning the code and using the docker-compose -f docker-compose-dev.yml build command, I got an error ERROR [build 5/7] RUN npm ci --silent . The problem was solved by changing the code RUN npm ci --silent on line 9 of the Nginx DockeFile to RUN npm install.

If possible, please complete this course and add the unfinished parts to the course, such as resetting the password in frontend and adding the subscription payment mechanism or production ready Email verification.

Finally, I sincerely thank you for sharing your knowledge and helping to develop new software.

Best regards
Hamed Asgari

GDPR user account

What is needed to supply is:

  • button to remove users' account available for user
  • remember the last activity on the user account so that not used accounts will be removed
  • automatically sending a message to the user that his account was deleted
  • checked box about terms of service and privacy policy before registration account (not pre-checked according to privacy by default rule) and about marketing stuff and
  • the automatically remembered date and the content of gave consent! (important)

Make 'init-letsencrypt.sh' executable

OMG! "I have deployed my first app into production." Brother, I would like to thank you for your kindness and brilliant fully comprehensive tutorials. I am sure that it helped many others like me.

When I go back to the comment, the 'init-letsencrypt.sh' certification file should be executable before use. We can make it executable in linux using this command: "sudo chmod +x init-letsencrypt.sh"

Thanks again!

Project not running with Docker

Hello

Maybe I am skipping something but when trying to run docker-compose -f docker-compose-dev.yml up, I get error in my terminal

django_redis_test_backend_1 exited with code 1
backend_1  | standard_init_linux.go:219: exec user process caused: no such file or directory

It also shows something about nginx config files but I am not sure about that.

| /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
nginx_1    | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
backend_1  | standard_init_linux.go:219: exec user process caused: no such file or directory
nginx_1    | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
nginx_1    | 10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
nginx_1    | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
nginx_1    | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
nginx_1    | /docker-entrypoint.sh: Configuration complete; ready for start up

I also cloned repo and tried again, but the error persists.
Could anyone help me figure out what could cause that or is it a general issue?

Thanks for tutorial anyway!

How to deploy Frontend and backend separately

Hi, Just want to know about the deployment settings for the project and how we will deploy frontend and backend separately
like both would be entirely independent of each other and we will be calling apis from frontend.

Messed with this quite a time hence need some guidance.

Lesson 3, missing instruction to amend apps.py inside accounts folder at "./manage.py migrate"

The command returned the following error:

django.core.exceptions.ImproperlyConfigured: Cannot import 'accounts'. Check that 'apps.accounts.apps.AccountsConfig.name' is correct.

It can be resolved by going to:
backend/server/server/apps/accounts/apps.py

and changing from

from django.apps import AppConfig

class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'accounts'

to:

from django.apps import AppConfig

class AccountsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.accounts'

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.