make sure to update the "projectname" "src": "<projectname>/wsgi.py", points to the wsgi.py file of your project "outputDirectory": "ui/staticfiles" tells vercel where to look because I have the static and staticfiles directories in the app called ui instead of root directory
step 3
tell where the static and staticfiles directories are located:
Set up and deploy “~/<path_of_your_project>”? [Y/n] y
? Which scope do you want to deploy to? <your_github_name>
? Link to existing project? [y/N] n
? What’s your project’s name? <name_of_project>
? In which directory is your code located? ./
🔗 Linked to <your_github_name>/<name_of_project> (created .vercel and added it to .gitignore)
🔍 Inspect: https://vercel.com/<your_github_name>/<name_of_project>/<vercel_specifics> [5s]
To deploy to production (<name_of_project>.vercel.app), run `vercel --prod`
❗️ Due to `builds` existing in your configuration file, the Build and Development Settings defined in your Project Settings will not apply. Learn More: https://vercel.link/unused-build-settings
Enter fullscreen mode Exit fullscreen mode
to run the deployed Django app on vercel, run:
vercel --prod
Enter fullscreen mode Exit fullscreen mode
We need to install several libraries and dependancies:
C) install the PostgreSQL database adapter to communicate to the database:
# install inside the virtual environment of your project:
pip install psycopg2
pip freeze > requirements.txt
Enter fullscreen mode Exit fullscreen mode
use the pip freeze > requirements.txt to save the new installed package inside the requirements.txt file
D) Create the database and a user:
We use the PostgreSQL database adapter to create a database and a user:
sudo -u postgres psql
Enter fullscreen mode Exit fullscreen mode
first we create the database named: "mydb"
CREATE DATABASE <mydb>;
Enter fullscreen mode Exit fullscreen mode
end the command with a semicolon!
create a user "myuser" with password "mypass":
CREATE USER <myuser> WITH ENCRYPTED PASSWORD '<mypass>';
Enter fullscreen mode Exit fullscreen mode
optimize PostgreSQL's settings:
ALTER ROLE <myuser> SET client_encoding TO 'utf8';
ALTER ROLE <myuser> SET default_transaction_isolation TO 'read committed';
ALTER ROLE <myuser> SET timezone TO 'UTC';
I was facing the question: How can I deploy my Django project on Vercel?
My requirements:
Enter fullscreen mode Exit fullscreen mode
I had already an account on Vercel and the vercel-cli installed.
step 1
create in root directory of your project the file:
build_files.sh
and add these lines of codeEnter fullscreen mode Exit fullscreen mode
step 2
create in root a
versel.json
file, which is the configuration for the versel deployment:Enter fullscreen mode Exit fullscreen mode
make sure to update the "projectname"
"src": "<projectname>/wsgi.py",
points to the wsgi.py file of your project"outputDirectory": "ui/staticfiles"
tells vercel where to look because I have the static and staticfiles directories in the app called ui instead of root directorystep 3
tell where the static and staticfiles directories are located:
Enter fullscreen mode Exit fullscreen mode
NOTE: If in your project the static directory is in root directory:
Enter fullscreen mode Exit fullscreen mode
Enter fullscreen mode Exit fullscreen mode
step 4
Integrate the PostgreSQL database into the Django project:
Enter fullscreen mode Exit fullscreen mode
to create a PostgreSQL database look at the end of this article
step 5
update the allowed hosts to give vercel access and being a valid host name:
Enter fullscreen mode Exit fullscreen mode
step 6
create the vercel variable
app
in your Django projectEnter fullscreen mode Exit fullscreen mode
step 7
add the static folder to the urls of your project
Enter fullscreen mode Exit fullscreen mode
step 8
open terminal:
Enter fullscreen mode Exit fullscreen mode
The vercel cli will ask you:
Enter fullscreen mode Exit fullscreen mode
to run the deployed Django app on vercel, run:
Enter fullscreen mode Exit fullscreen mode
We need to install several libraries and dependancies:
A) install PostgreSQL:
Enter fullscreen mode Exit fullscreen mode
B) install dependencies necessary for Linux:
Enter fullscreen mode Exit fullscreen mode
C) install the PostgreSQL database adapter to communicate to the database:
Enter fullscreen mode Exit fullscreen mode
use the
pip freeze > requirements.txt
to save the new installed package inside the requirements.txt fileD) Create the database and a user:
We use the PostgreSQL database adapter to create a database and a user:
Enter fullscreen mode Exit fullscreen mode
first we create the database named: "mydb"
Enter fullscreen mode Exit fullscreen mode
end the command with a semicolon!
create a user "myuser" with password "mypass":
Enter fullscreen mode Exit fullscreen mode
optimize PostgreSQL's settings:
Enter fullscreen mode Exit fullscreen mode
these parameter are recommended by Django docs
grant permission to the user:
Enter fullscreen mode Exit fullscreen mode
addapt the name of the database and the user name
quit the SQL prompt
Enter fullscreen mode Exit fullscreen mode
E) Integrate the PostgreSQL database into the Django project:
Enter fullscreen mode Exit fullscreen mode
For production or hosting on Vercel the better version will be to store sensitive information in the
.env
file in root of your project.To be able to use a
.env
file in your project we need to install:Enter fullscreen mode Exit fullscreen mode
use the
pip freeze > requirements.txt
to save the new installed package inside the requirements.txt fileEnter fullscreen mode Exit fullscreen mode
add a new file
.env
in root of your project:Enter fullscreen mode Exit fullscreen mode
finish the creation of the PostgreSQL database with
Enter fullscreen mode Exit fullscreen mode
Hope this post helps!