Note: Since we will be progressing with the project, we will be using the backend
folder in the root of this repository as our project folder. So, make sure you have cloned this repository in your system.
You have to create a python virtual environment for your project. You can use the venv
module to create a virtual environment. You can refer to the official documentation for more details.
- Create a virtual environment named
venv
in thebackend/
folder. - Make sure to add this folder to the
.gitignore
. You can check out various.gitignore
templates for Django/Python. - Activate the virtual environment.
- Install Django in the virtual environment using
pip install django
.
You have to create a Django project. You can refer to the official documentation for more details.
- Create a Django project. Name it
mydjangoproject
for consistency. - Make sure the project directory is at
summer-of-code-2023/backend/mydjangoproject
- Run the server and check if it is working.
- Create a Django app. You can name it anything you like. Add the app to the project and make necessary changes in the
settings.py
file. - Write basic code for the app and check if it is working.
You have to create models for your app and render templates using the models. You can refer to the official documentation for more details.
- Create models for your app. You can start by creating a model
Product
which will have fields likename
,description
,price
, etc. - Apply migrations and add some fictional data to the database using the admin panel.
- Create templates for your app. You can start by creating a webpage to display all the products.
You have to add authentication to your project. You can refer to the official documentation for more details.
- Create a basic login page and a signup page.
- Create POST methods for both the pages and add the necessary logic.
- The page must display Login if the user is not logged in and Logout if the user is logged in.
You have to create a form for adding products to the database. You can refer to the official documentation for more details.
- Create a form for adding products to the database.
- Make sure the form is only accessible to authenticated users.
- Add the necessary logic to add the product to the database.
- Visualise your schema! Create a file
backend/schema.md
and write each field and their data type etc. for each Model in table format in markdown, keeping a separate Table for each Model. Also, create a diagram for your schema using Mermaid. - By default, Django uses
sqlite3
as its database for development. However, for production, you need to set up a database like MySQL or PostgreSQL. So, for the first bonus task, setup PostgreSQL on your local machine and connect it to Django - When using Django on production, we prefer a different server like
nginx
orapache
for rendering the static files like the templates and assets. So, set up a simple nginx static server, and place your static files accordingly - Django server runs on port 8000 usually. However, port 80 is used to listen to HTTP traffic in a server. Although it may seem straightforward, the catch here is that 80 and 443 are privileged ports, so it is an unsafe practice to allow Django to use them directly. Now, setup a reverse proxy on nginx to forward traffic to and from port 80 to 8000