Deploying TO-DO App in Local Virtual Machine

Deploying TO-DO App in Local Virtual Machine

Setup Virtual Environment

To Install the Virtual Environment run the following command

py -m pip install --user virtualenv

Now, to create the virtual environment

py -m venv env

here env -> Name of the virtual environment(you can name as per choice also)

After that to activate the virtual environment, run the command

env\Scripts\activate.bat

Setup Server

To get this repository, run the following command inside your git-enabled terminal

git clone https://github.com/harshitsahu2311/Django-todo-automate.git

After that, you have to switch to the Django-todo directory

cd Django-todo

You will need Django installed on your computer to run this app.

pip install django

Head over to https://www.djangoproject.com/download/ for the download guide

Once you have downloaded Django, go to the cloned repo directory and run the following command

python manage.py makemigrations

This will create all the migrations file (database migrations) required to run this App.

Now, to apply these migrations run the following command

python manage.py migrate

One last step and then our todo App will be live. We need to create an admin user to run this App. On the terminal, type the following command and provide username, password, and email for the admin user

python manage.py createsuperuser

That was pretty simple, right? Now let's make the App live. We just need to start the server now and then we can start using our simple todo App. Start the server by following the command

python manage.py runserver

Once the server is hosted, head over to http://127.0.0.1:8000/todos for the App.

COOL!!! You have Done it.

Now to run this same server on any other IP you just have to mention it before the above command.

python manage.py runserver 0.0.0.0:8000

Output:-

But if you get this error while accessing the todo-app:

then you have follow some steps -

firstly, open go to the settings.py file of this app

cd todoApp
vi settings.py

Here you have to change the permission of Allowed host to grant everyone by adding this ['*']

After this refresh the screen

Finally you have done it.....

Now If you want to run this server on background so that you can access terminal also while running this app, run the following command

nohup python manage.py runserver 0.0.0.0:8000 &
What is nohup command?
It allows you to run a command or shell script in such a way that it continues to run even after you log out or close the terminal.

![](cdn.hashnode.com/res/hashnode/image/upload/.. align="center")

Now to list the running services run the command

lsof -i:8000
What is lsof?
The 'lsof' command in Linux is a utility that provides information about files that are opened by processes.

Now to stop the running server

kill -9 PID

Done you have successfully closed the server...