Git Product home page Git Product logo

django-example's Introduction

django-example

This repository is intended to show how to use pagination in Django

Requirements

  • Docker
  • Docker-Compose

How to run the application

  1. Go to the repository folder (cd <path/to/repository>)

  2. Build the files (docker-compose build)

  3. Migrate the database (docker-compose run web python manage.py migrate)

  4. (Optional) Generate sample users to show how the application works (100, for example)

    docker-compose run web python manage.py generate_fake_data 100

  5. start the application. docker-compose up

Testing

This application uses pytest for testing. The following things have been tested:

  • Address creation / field constraints
  • Pagination
  • Page range

If you want to execute the tests, you must write:

  • docker-compose run web pytest

Additional information

Although the application works well, the users and passwords are visible inside the code. If you want to deploy the application in the cloud (aws, gcloud, your own vps, etc.) you must use your own passwords. This program facilitates this task by having a command to generate sample users and passwords. You can type make generate-sample-envs to generate sample env files inside .envs folder. Then. you will have the following files with this values:

.envs/.web

SECRET_KEY=secret
DJANGO_SETTINGS_MODULE=config.settings.local

.envs/.db

POSTGRES_USER=sample
POSTGRES_PASSWORD=sample
POSTGRES_DB=sample

It is recommended to change the values and put your own ones, because they are insecure since they are visible

Production

If you want to deploy the application, there is a configuration file called prod.yml with:

  • Setup for NGINX server
  • Setup for serving static and media files
  • Setup for gunicorn server (we are executing the Django application here)

It is needed to perform the following steps to successfully deploy the application:

  1. Generate env variables, with make generate-sample-envs
  2. Change the variables so we app is more secure
  3. Build everything with docker-compose -f prod.yml build
  4. Collect static files with docker-compose -f prod.yml run web python manage.py collectstatic, so NGINX server can serve them
  5. Start the application with docker-compose -f prod.yml up

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.