Implementing Django and Vue – Building a Social Network with Django and Vue 3 | Part 15

Posted by


In this tutorial series, we have covered the development of a social network using Django and Vue. Now, we will walk you through deploying the application so that it can be accessed by users on the internet. We will cover the steps required to deploy both the Django backend and the Vue frontend on a cloud server.

Before we start, make sure you have the necessary tools and accounts:

  1. A cloud server (such as AWS, DigitalOcean, or Heroku) with root access
  2. An SSH client (such as PuTTY or Terminal)
  3. Docker installed on the server
  4. Docker Compose installed on the server
  5. Git installed on the server

Now, let’s get started:

  1. Prepare the Django backend:
    First, clone the Django backend repository to your server using Git:

    git clone <repository-url>
  2. Prepare the Vue frontend:
    Next, clone the Vue frontend repository to your server using Git:

    git clone <repository-url>
  3. Configure Django settings:
    Update the Django settings file to include the production settings, such as the database credentials, allowed hosts, and static files settings.

  4. Build the Vue frontend:
    Navigate to the Vue frontend directory and build the production version of the frontend:

    npm install
    npm run build
  5. Create a Dockerfile for the Django backend:
    Create a Dockerfile in the root directory of the Django backend to define the environment for running the Django application:

    
    FROM python:3.9

ENV PYTHONUNBUFFERED 1

WORKDIR /app

COPY requirements.txt .

RUN pip install -r requirements.txt

COPY . .

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]


6. Create a Dockerfile for the Vue frontend:
Create a Dockerfile in the root directory of the Vue frontend to define the environment for running the Vue application:

FROM node:14

WORKDIR /app

COPY package.json .

RUN npm install

COPY . .

EXPOSE 8080

CMD ["npm", "run", "serve"]


7. Create a docker-compose.yml file:
Create a docker-compose.yml file in the root directory to define the services and their configurations:

version: ‘3’

services:
backend:
build: .
ports:

  • "8000:8000"
    frontend:
    build: .
    ports:
  • "8080:8080"
  1. Build and run the Docker containers:
    Build and run the Docker containers using Docker Compose:

    docker-compose up -d
  2. Access the application:
    You can now access the deployed application using the IP address or domain name of your cloud server. The Django backend should be running on port 8000, and the Vue frontend should be running on port 8080.

That’s it! You have successfully deployed the Django and Vue social network application on a cloud server. Users can now access the application on the internet and interact with each other. Thank you for following along with this tutorial series. If you have any questions or run into any issues, feel free to reach out for help. Happy coding!

0 0 votes
Article Rating
9 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@user-iz1rt5pj4u
1 month ago

Stein, hello!
Thank you for your time and attention to detail. I'm your big fan!
Tell me, how on this site could you access Django admin as a superuser? http://domain/admin/ will not work in our case?

@davidadu1113
1 month ago

Great tutorial

@ell3r0se
1 month ago

This series was fantastic! I would love to see some follow up videos with the other ideas you had if you ever decide to do that. Thank you so very much 😊

@mahmoudessam7525
1 month ago

Your tutorial was amazing Thank you so much for your efforts 🙂

@RambleOnRose42
1 month ago

Your tutorial was amazing!!! Thank you! I used this as a jumping off point to make my own recommendation-based social media app. I have a question though: if I made changes to my app, how do I get those changes into my DigitalOcean droplet? Do I need to start the process over from scratch? Because when I try to remove the old backend folder and replace it with a new one, it says "cannot remove: backend is a directory". Do you have a video for linking through Github?

@TechForgeinstitute
1 month ago

Your tutorials are always amazing, so the attachment part of this tutorial, instead of using imageField, I used FileField and added a validator to allow just image and videos, now in d frontend I don't want to show image if a video is uploaded, how to i do this in Vue

@5ov4-94
1 month ago

Thank you!

@extra12121
1 month ago

Thank you, when there is a friend request, I press accept several times and a lot of friends are added. Is this the same for you?

@geniculata_spider
1 month ago

Thank you 🙏