Set Up Your Venv, Django, and GeoDjango
It’s finally time to get started on our Django project and get to work in Python. We’ll start by creating a virtual environment, then install Django with Pip, and then enable GeoDjango.
Make sure you have the following items installed and working before you continue:
- PostgreSQL with PostGIS
shopsdatabase with PostGIS extension; and
- Our geographic drivers, either installed on their own or as part of QGIS.
With that foundation in place you’re ready to start the web server portion of your project using the Django and GeoDjango frameworks.
Welcome to the fourth video in our series for building a location-based web application with Django and GeoDjango. It’s finally time to get started on our Django project and get to work in Python. We’ll start by creating a virtual environment, then install Django with
pip, and then enable GeoDjango.
Make sure to have the following items installed and working before you continue: PostgreSQL with PostGIS, a
shops database with the PostGIS extension, and our geographic drivers either installed on their own or as part of the QGIS application. With that foundation in place, you’re ready to start the web server portion of your project using the Django and GeoDjango frameworks.
Let’s start off by creating a new Python virtual environment. For full disclosure, I use PyCharm as my primary editor, and PyCharm automatically creates virtual environments for each new project. In addition, PyCharm provides point-and-click
pip installations and templates for popular frameworks like Django. If you use PyCharm as your editor, I encourage you to take advantage of these time-saving features. In this video, however, I will be completing these tasks by hand at the command line to keep the instructions universal. First, I create a new folder for my project called
Then, from within my new
geoshops/ folder, I’m going to create my Python virtual environment and activate it with the following two commands. After activating the environment, notice the context of the command prompt reflects this.
Notice your virtual environment’s subfolder there. Don’t make any changes to this. I will use PyCharm’s built-in terminal to install Django, and your editors should have a similar mechanism. But if it doesn’t, you can use the terminal or command prompt your operating system provides. Within the
geoshops/ folder, type the command
pip install django and press Enter.
The installation has completed successfully. The next step is to set up our Django project. While the
geoshops/ folder is our way of organizing our work into a project folder,
geoshops/ is not technically a project from Django’s point of view.
Once the script finishes, our Django
shops website is created. If we refresh the contents of our folder, we notice we have a new file
manage.py at the root of
geoshops/, along with a subfolder named
shops. Within the
shops/ folder, we have four files.
urls.py is there to route incoming requests to your site. You can think of it as a front desk reception for visitors to your website. We’re going to complete one more small task before ending this video.
Become a Member to join the conversation.