Code Monkey home page Code Monkey logo

django-app's Introduction

Django Logo

Django App

This repository contains a simple Django app as part of the Deploying a Production ready Django App on EC2 with CI/CD gist tutorial which you can find here

Table of Contents

Project Layout

Here is the project layout:

django-app
  |___ backend/ (Django Backend settings)
  |   |___ settings.py
  |___ static_files/
  |___ templates/ (Django Templates)
  |   |___ index.html
  |___ scripts/
  |___ manage.py
  |___ requirements.txt
  |___ Dockerfile
  |___ docker-compose.yml

The default settings are typically built for development rather than production and I found it difficult to change my settings after building the project. My inspiration comes from this article here: https://djangostars.com/blog/configuring-django-settings-best-practices/ where the different approaches are listed.

My approach uses the django-environ package (https://django-environ.readthedocs.io/en/latest/#) which makes it relatively easy to manage your development and production environment variables.

I have also included the django-debug-toolbar (https://django-debug-toolbar.readthedocs.io/en/latest/) which I found useful in debugging and optimizing Django, specifically when it came to how my app queries the database.

Note: Make sure to add the .env files to your .gitignore. They are not included by default in this project so that you have a reference to what type of data should be in there.

Requirements

  • Python 3.7+
  • Django 3.0+

Setting up the Django-app project with Docker

For those that are not interested in setting up the project manually or would simply not have to worry about downloading python and its dependencies, I have created a Dockerfile and docker-compose.yml file to help create a container with everything you would need to run the django-app.

Install Docker

To make this as easy as possible, we will be using Docker Compose to creat our container.

$ docker-compose --version
docker-compose version 1.26.2, build eefe0d31

Build and Run the Container

  • Clone the repo to your local machine:
$ git clone https://github.com/rmiyazaki6499/django-app.git
  • Go into the project directory to build and run the container with:
$ cd django-app/
$ docker-compose up --build

Navigate to http://localhost:8000 to view the site on the local server. It should look something like this:

django-default

Cleaning up the Container and Image

To stop the container from running, use <Ctrl-C> twice. To close down the container use the command:

$ docker-compose down

Then to clean up the container and image which we are no longer using use the command:

$ docker system prune -fa

Confirm that the container and image is no longer there with:

$ docker system df -v

Setting up the Django-app project manually

If you either did not want to use Docker or was curious to build the django-app manually follow the directions below.

  • On your terminal and clone the repository with Git:
$ git clone https://github.com/rmiyazaki6499/django-app.git
  • Next, go into the project directory and make sure you create a virtual environment for your project by either using venv or pipenv:
$ cd django-app/
$ python3 -m venv env
$ source env/bin/activate
$ pip3 install -r requirements.txt
  • We will now migrate the database and collect the static files:
$ python3 manage.py makemigrations
$ python3 manage.py migrate
$ python3 manage.py collectstatic
  • To run the development server, use the following command:
$ python3 manage.py runserver
  • To run the production server, use the following command:
$ ENV_PATH=.env-prod python3 manage.py runserver

Navigate to http://localhost:8000 to view the site on the local server. It should look something like this:

django-default

Author

Created by:

django-app's People

Contributors

rmiyazaki6499 avatar

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.