Before you can start to build the individual functionality of a new Django web application, you always need to complete a couple of setup steps. This tutorial gives you a reference for the necessary steps to set up a Django project.
The tutorial focuses on the initial steps you’ll need to take to start a new web application. To complete it, you’ll need to have Python installed and understand how to work with virtual environments and Python’s package manager, pip
. While you won’t need much programming knowledge to complete this setup, you’ll need to know Python to do anything interesting with the resulting project scaffolding.
By the end of this tutorial, you’ll know how to:
- Set up a virtual environment
- Install Django
- Pin your project dependencies
- Set up a Django project
- Start a Django app
Use this tutorial as your go-to reference until you’ve built so many projects that the necessary commands become second nature. Until then, follow the steps outlined below. There are also a few exercises throughout the tutorial to help reinforce what you’ve learned.
Free Bonus: Click here to get access to a free Django Learning Resources Guide (PDF) that shows you tips and tricks as well as common pitfalls to avoid when building Python + Django web applications.
Prepare Your Environment
When you’re ready to start your new Django web application, create a new folder and navigate into it. In this folder, you’ll set up a new virtual environment using your command line:
$ python3 -m venv env
This command sets up a new virtual environment named env
in your current working directory. Once the process is complete, you also need to activate the virtual environment:
$ source env/bin/activate
If the activation was successful, then you’ll see the name of your virtual environment, (env)
, at the beginning of your command prompt. This means that your environment setup is complete.
You can learn more about how to work with virtual environments in Python, and how to perfect your Python development setup, but for your Django setup, you have all you need. You can continue with installing the django
package.
Install Django and Pin Your Dependencies
Once you’ve created and activated your Python virtual environment, you can install Django into this dedicated development workspace:
(env) $ python -m pip install django
This command fetches the django
package from the Python Package Index (PyPI) using pip
. After the installation has completed, you can pin your dependencies to make sure that you’re keeping track of which Django version you installed:
Read the full article at https://realpython.com/django-setup/ »
[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]
from Planet Python
via read more
No comments:
Post a Comment