If you are looking to get started with the Django development server on your laptop, you have come to the right place. In this blog post, we will discuss how to set up the Django development server on your laptop so that you can develop and run applications using Django. We will also cover what Django is and what the Django development server does. By the end of this post, you will be ready to start creating and running applications with Django on your laptop. So let’s get started!
What is Django?
Django is a high-level, open-source Python web framework that simplifies the development of web applications. It’s designed to be fast and secure, with a powerful set of features and a robust ecosystem of packages and libraries to help developers create their apps quickly.
Django helps developers build complex, database-driven websites and web applications, as well as providing an easy-to-use admin panel for managing content and user accounts.
Django’s design is based on the popular Model-View-Template (MVT) pattern, which separates the data, logic, and presentation layers of an application. This makes it easier for developers to focus on building their apps without having to worry about managing different parts of their application stack. Django also has a robust security model, providing support for authentication and authorization out of the box.
What is the Django Development Server?
The Django Development Server is a lightweight web server that enables developers to test and debug their applications. This server was created to allow developers to work on their applications without having to setup a production server. The Django Development Server is based on the popular web server software, WSGI.
Overall, the Django Development Server is a great tool for developers looking to quickly test and debug their application. With its simple setup process, the server makes it easy for developers to get up and running in no time.
Setting up the server
This guide will show you the steps you need to follow to create a local Django development environment – tested on Windows (using the WSL) and Ubuntu Linux. As always, proceed with caution when following technical guides.
First of all then, we need to update our libraries
sudo apt update
Next, we need to install Django, we can go ahead and check the version after install.
sudo apt install python3-django django-admin --version
Now let’s create a directory for our application to reside in and navigate to that directory.
mkdir ~/django-test cd ~/django-test
Now, we need to create our virtual environment. To install the Virtual Environment library, create the virtual environment & active it, we use:
sudo apt install python3.10-venv python3 -m venv my_env source my_env/bin/activate
Next, let’s install Django inside our virtual environment:
pip install django
And now create our Django project. I’ve just called this one djangoproject for test purposes, but you can call it whatever you like.
django-admin startproject djangoproject
Next, let’s make our first migration and create a superuser. You’ll be prompted to provide details for the superuser. This user can login to the admin portal.
python manage.py migrate python manage.py createsuperuser
Next we can create an app to live within our project. You can call this whatever you like, but I’ve just called it ‘app’.
python manage.py startapp app
Finally, you should now be able to run the Django development server & test your install has worked:
python manage.py runserver 8080
From here, you should be able to navigate to http://localhost:8080/ from your web browser & the app should appear.
Hopefully this will help you to quickly get an app running locally – you’re now free to get developing!