1. Home
  2. Windows Tips
  3. How to install django on windows server

How to install Django on Windows Server

Django is an open-source Python web framework that has a lot of advanced features like URL routing, form handling, etc. As a result, it’s hugely popular with developers. Here’s how to get Django working on Windows Server.

How to install Python on Windows Server

Django requires Python to function on Windows Server. As a result, you’ll need to install Python. There are quite a few ways to get Python working on Windows Server. However, the easiest is to deploy the Chocolatey package management tool and install it that way.

 

To install Chocolatey, start by launching a PowerShell window on the Windows Server desktop. Once it is open, execute the following commands into the prompt.

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

After running the commands above, Chocolatey will be installed. However, you’ll need to close the PowerShell window and re-open it. Once it is open, use the choco install command to install Python.

choco install python

The Python installation will take a bit. When it is complete, close the PowerShell window a second time, and re-open it. Once it is open, you can launch the Python interpreter to test and see if it is working correctly on your system.

python

Assuming it is working, you can exit the Python interpreter using the exit() function.

exit()

How to install PostgreSQL on Windows Server

If you are developing with Django, you’ll likely need a database to interact with your application. There are many databases to choose from. However, one of the best options for database integration with Django is PostgreSQL. Here’s how to get it working.

PostgreSQL can be installed on Windows Server by downloading the installer, or by using Chocolatey. In this guide, we’ll use Chocolatey. To start, launch a PowerShell window. Once it is open, you can use the choco install command to install PostgreSQL on your Windows Server.

choco install postgresql

During the installation process, PostgreSQL will generate a password for you to use for the postgres user. This password is displayed in the PowerShell. Copy this password to log in after the installation.

Once the Chocolately package tool is done installing PostgreSQL on your Windows Server, you’ll need to close the PowerShell window and re-open it. When it is open, use the psql -U command to log in.

psql -U postgres

Log into PostgreSQL using the generated password. Then, use the following command to change the password to something more secure. Be sure to alter the “new_password” aspect of the command below with your desired password.

ALTER USER postgres WITH PASSWORD 'new_password';

With the password changed, you’re ready to use PostgreSQL with your Django application on Windows Server.

How to install Django on Windows Server

Django is installed via Python. Specifically, the Python package manager Pip. To start the installation for Django, open up the PowerShell window as Administrator. When it is open and ready to use, you can run the pip install command to install the “django” package.

pip install django

The installation for Django is pretty quick. However, just because you’ve installed the “django” package with Python’s Pip package manager, that doesn’t mean it’s ready to use.
You need to create a new Django project.

You must create a new Django project on Windows Server to start using it. To create a new project, use the django-admin command below in the PowerShell window.

django-admin startproject my_app

In this example, the new Django project is “my_app”. As a result, you’ll see a folder created in your path. If you are unsure what your path is, execute the pwd command to display it.

pwd

Once you’re aware of the path, run the ls commands to view the contents of it.

ls

Look through the ls command output for “my_app” to ensure that Django created the directory successfully. When you’ve found it, use the cd command to enter this directory.

cd .\my_app\

When you’ve accessed the new folder, you can start the Django development server on your Windows Server using the python command below. Keep in mind, this server will only run as long as the PowerShell window is open and running.

python manage.py runserver

Once the Django development server is running on Windows Server, you can access it at the following URL:

http://localhost:8000/

To close the Django development server, close the PowerShell window.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.