How to Setup and Deploy Project in Django Framework
Published: 2023-07-14 04:46:18


I.	Setup
A.	Install Python
1.	Go to Python’s official website: https://www.python.org
2.	Go to Downloads section.
3.	Click on the download link of your desire version to download the Python’s installer
4.	When you activated the installer, it is recommended to go with the default setting that the installer has. However, if for some reasons the default setting does not add Python to Path, then you need to click that option.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ynk3vqpwxajriw85lk4z.png)


5.	Also click on install pip option.
6.	You should be good to go for this section

B.	Install Visual Studio Code
1.	Go to https://code.visualstudio.com/
2.	Click on Downloads for <your os name> which will install the installer
3.	Walk through the installer, default setting is again recommended but you can create a desktop icon if you want to.
4.	When you first open VS code, they will ask you for your preferred theme, but there is nothing else you need to do for your Django project, yet.

C.	Install Django
Note: In the following step I tried to make it simple in my personal experience, but it can vary. However, the result of all the steps are the same.
1.	Create a folder at any location that is convenient for you. I will call it YourFolder, but you can call whatever you want.
2.	Open VS code and click open new folder.
3.	Select YourFolder.
4.	Click on “View” on the top bar and click on Terminal
5.	In the terminal, type:
**python -m venv venv**
This is to create an environment so whatever you install or work here will not affect your machine. The second “venv” is the whatever name you want to give to your environment.
6.	After the environment is created, you will need to activate the environment every time you use Django project.
7.	To activate the environment, you first need to locate to Script. In your terminal, your current location should be at your folder. Your folder should contain the environment that you created. Type:
Cd Scripts
This command will get you there.
8.	Then to activate, you type:
**activate**
Or 
**.\activate**
“activate” works on some of the machine, but some need you to use the second command.
9.	Now that you activate your environment, you will install Django at that location by the following command.
**Pip install Django**
10.	Then create a Django project with the following command.
**django-admin startproject your_project_name**
11.	To see if it work, type the following command to run a local server:
**Python manage.py runserver**

II.	Deploy
A.	Create Vercel Account
1.	Click “Sign up” and enter your username.
2.	If you haven’t have git hub account then you need to create one.
3.	In Vercel, click “Continue with Github”

B.	Prepared your project before uploading to Github
1.	In the settings.py file of your project. Change the “ALLOWED_HOST” to this:
ALLOWED_HOST=[“.vercel.app”]
2.	In the wsgi.py file of your project, set:
app=application
3.	In your project create requirements.txt using the following command in the terminal:
Pip freeze > requirements.txt
4.	Create a file call vercel.json in the same location as requirements.txt
5.	In the vercel.json file type:
{

    "builds": [{

        "src": "djangoprojectname/wsgi.py",

        "use": "@vercel/python",

        "config": { "maxLambdaSize": "15mb", "runtime": "python3.9"
 }

    }],

    "routes": [

        {

            "src": "/(.*)",

            "dest": "djangoprojectname/wsgi.py"

        }

    ]

}


C.	Deploy
1.	Upload your all the files in your project to Github in a new repository. Just drag the project in the select section.
2.	In Vercel, add github account and select your github account in select git namespace.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qtbbb9c19n3bfjuu9q6.png)


3.	Choose “only select repositories” option, and choose the repository that you just created.
4.	Click “Install”
5.	Click “import”
6.	Your root directory should be the top file of your project not simply the repository name.
7.	Click “Build”