To start a Django project, you just need a computer with an operating system, a text editor, and some knowledge about software development. But is it really convenient and efficient to program this way? In this article, I’ll show you how to speed up your work and make it more comfortable – both for you and your colleagues.
Here’s a step by step guide to setting up a Django development environment, starting from the basics.
Note 1: If you’re a beginner developer and need more information about Django, read this article: What is Django and how to get started?
Note 2: A programming setup is subjective, and only you can decide what is the best option for you. At the end of this article, I share my personal configuration for programming to give you an example.
1. Choose your operating system
Just as a reminder, here’s a short definition of what an operating system is:
An operating system (OS) is the software which controls the hardware and keeps everything together. The OS communicates with all the computer devices, manages them, and controls their actions (for example, a mouse and keyboard).
An operating system also includes a lot of built-in software like the common system services, libraries, and application programming interfaces (APIs) developers can use to write programs that run on the operating system.
Operating systems for Python development
Python developers usually use one of these two operating systems:
Mac OS X
Apple’s operating systems are well-synchronized with their hardware. What’s notable here is the navigation. Users can quickly move over all windows using only gestures and keyboard. I often end up not even using the mouse. In my opinion, the mouse is not convenient and slows work down. The user interface is nice and powerful. Searching for functionalities is easy. Installation of new things is as easy as possible. The biggest cons of Mac OS X is cost and compatibility with other hardware than the dedicated one.
- user interface (powerful and simple),
- navigation using gestures,
- fewer viruses and security issues,
- very easy and intuitive,
- great integration between OS and hardware,
- just convenient.
- limited hardware choice.
TIP: Install a package manager called Homebrew. It will make the installation of different software solutions easier.
TIP: I really recommend Mac OS X, because you get to focus on programming and not configuring or solving different problems.
Linux is a great option for both beginner and advanced programmers. You can choose from a variety of distribution options that match your preferences and customize almost everything (but note that it often takes more time than on e.g. OS X). The design is nice too. The standard navigation is not sufficient, but you can configure it. The Linux community is really helpful and can help you solve any problem. Sometimes drivers for Linux may not be available, but in most cases it’s not an issue.
The most popular distributions are:
- Debian GNU/Linux,
- Arch Linux,
Advantages of Linux:
- free to use,
- helpful community,
- variety of distributions,
- less support for drivers,
- more complicated.
Unlike most Unix systems and services, Windows doesn’t include a system-supported installation of Python, but that doesn’t mean that you can’t program on Windows. The design is nice, you can customize most things and set them up as you like. It’s also cheaper than Mac OS X. At the beginning, you may have to install some things (for example, Python), but it takes just a few minutes.
- nice user interface,
- easy and intuitive,
- community support,
- hardware support.
- more threats, viruses,
- some of packages may not work properly.
2. Pick your text editor
I’ve been using Sublime Text 3, and I recommend it. You can customize this program to fit your preferences easily. There’s a plugin for everything, I think. Some of my colleagues also use this text editor and I’ve never seen that program look the same (and I’ve seen quite a few configurations).
I recently decided to try something new and installed a text editor called Visual Studio Code. Why that one? I’ve searched for something free, had similar functionalities to Sublime, and provided a terminal option in the text editor. The results are really promising so far and I plan to try it in my commercial projects.
Even if you find a tool that is good enough, take some time to test something new. You might find a better editor or just gain new insights or inspiration.
TIP: Look for helpful plugins which improve your productivity. If you’re a Python developer, it’s smart to pick tools that include features such as syntax correctness checking.
Great text editors for Python/Django developers
PyCharm – an integrated development environment for Python’s JetBrains programming language. It provides, among others, editing and analysis of source code, graphical debugger, running unit tests, and integration with the version control system. It also supports the programming and development of web applications in Django. You can download paid or free version. There exist a few different versions of this IDE.
Sublime Text – a cross-platform, expanded, and highly configurable text editor written in C ++ and Python. You can download and use it for free. However, the free version will display a message encouraging you to register and take advantage of its full, paid version.
Vim is a highly configurable text editor for creating and changing any kind of text. It is included as “vi” in most UNIX systems and Apple OS X. Vim is rock-stable and continuously developed to become even more efficient.
Visual Studio Code – a free text editor with coloring for many languages, created by Microsoft and distributed under the open-source MIT license. This text editor offers a set of interesting functions, a refined graphic interface, lightness, and speed of operation.
3. Choose your terminal
Sometimes you get a built-in terminal in your text editor. Otherwise, you can install a terminal as a plugin to your editor. That’s a convenient option.
Should I install another terminal or use the default one?
An answer is simple: it all depends on what you need. But let’s take a closer look at this matter.
Start by asking yourself these questions:
Do you often test your code in shell?
Do you use the terminal for integration with version control system or do you accomplish that with an app?
Then the answer is yes, installing another terminal will make sense for you. Anyway, it’s a huge convenience.
Is your use of terminal limited to running some commands?
Then the answer is no. For example, if you just need run a project and you’re committing changes using special a program.
TIP: Whether you’re using a default terminal or not, I encourage you to improve your terminal by installing tools like Oh My Zsh to make it more interactive.
The best terminal alternatives for macOS
iTerm2 – this terminal is the closest to a go-to replacement for the MacOS Terminal app. Plenty of people who work on the command line install iTerm2 when they set up their Mac and then never even think about any of the alternatives. One of the main features iTerm2 supports is split panes. While the Mac Terminal app supports tabs (which iTerm2 does as well), split panes help to keep an eye on what you’re working on.
Alacritty – a terminal emulator with a strong focus on simplicity and performance. Performance is the key word here. Contrary to many terminal apps, Alacritty uses your graphics card to accelerate its performance. That means scrolling through long screens is much smoother than many other apps.
Terminator has been around for years and offers some features you won’t find in other terminal apps. One of them is the drag-and-drop support, which lets you drag and drop a folder or file from Finder into the terminal window. This automatically inserts the file name as text, which can be useful.
The best terminal alternatives for Linux
Terminator is an open-source and cross-platform terminal emulator developed in Java. Based on the Gnome Terminal, Terminator adopts most of its features and gets updated as soon as Gnome Terminal gets updated. If you’re a programmer or a system administrator and work on multiple tasks at same time, the Terminator will be useful as it helps to split multiple tasks into individual panes under a single window.
Tilda a terminal emulator which is more or less similar to popular terminal emulators such as Gnome Shell, Konsole and xterm, etc. But it has some features you will not find in any other regular terminal emulator. Tilda is not a full-window terminal emulator – instead it can be pulled down and up from the top of desktop screen.
Alacritty is a terminal emulator with a strong focus on simplicity and performance. The included features were carefully considered and you can always expect Alacritty to be blazingly fast. By making smart choices for defaults, Alacritty requires no additional setup. However, it allows the configuration of many aspects.
4. Check out these great development tools (optional)
Postman – it’s a great tool for managing all of your projects with APIs. You can easily make a lot of different kind of queries to API, save them, and collect in virtual folder. You can even share that folder with others.
GitHub Desktop is designed to simplify the all processes and workflows in your GitHub. It offers a fast and easy way to contribute projects.
On our blog, you will also find an article about what a typical web development workflow looks like – be sure to check it out!
Advanced REST client – it’s a great plugin for Chrome that helps to make custom requests to different pages. An excellent tool for testing APIs.
Docker is a tool designed to help developers create, deploy, and run applications by using containers. Containers allow packaging up an application with all the parts it needs, such as libraries and other dependencies, and ship it all out as a single package. Docker is a little bit like a virtual machine. It also includes a great tool called “Compose” for defining and running multi-container Docker applications.
DBeaver – free, multi-platform database tool for developers, SQL programmers, database administrators, and analysts. Supports all popular databases.
IPython – Interactive Python is a command shell for interactive computing in multiple programming languages. Originally developed for the Python programming language, the tool offers introspection, rich media, shell syntax, tab completion, and history.
Refined GitHub – a browser extension that simplifies the GitHub interface and adds some useful features.
Zsh is a shell designed for interactive use, although it is also a powerful scripting language
Oh My Zsh is an open-source, community-driven framework for managing your zsh configuration.
HTTPie is a command-line HTTP client. Its goal is making CLI interaction with web services as human-friendly as possible. It provides a simple http command that allows sending arbitrary HTTP requests with the help of simple and natural syntax. It also displays colorized output. HTTPie can be used for testing, debugging, and generally interacting with HTTP servers.
5. Example – my Django development setup
OS X – I work using this OS and I’m not going to change it anytime soon. First of all, macOS is convenient. I don’t have to think “how to do something” and search for solution on the internet. OS X is intuitive and easy. It’s pretty nice that developers do can a lot of things here that they can do also on Linux but without the fear that something will go wrong.
Sublime Text 3 – I chose this text editor because it’s very customizable, has great packages and support from the community, and is free.
I have installed these packages:
- Anaconda – a plugin that turns Sublime Text 3 into a richly featured Python development stack that boosts your productivity and ensures the high quality and style of your code.
- Djaneiro – Django support for Sublime Text.
- GitGutter – a Sublime Text plugin for showing information about files in a git repository.
- Python 3 – Python 3 and Cython language bundles for Sublime Text and TextMate.
- “Theme – Flatland” – a nice theme for Sublime. I use the color and theme called “Flatland Dark”.
iTerm2 – this one is a nice replacement for the default terminal. It’s easy to customize.
I encourage you to install Oh My Zsh to make the terminal more interactive. IPython comes in handy as well – for example, for testing code samples.
Postman – I use this app during development for testing the API and collecting created URLs. It’s really helpful when I have ready-to-use requests. What I need to do is only modify the request a little or click send to test it. Postman also offers a built-in special tool for testing. The history of requests also is available.
Docker – I can’t imagine development without this tool. The ease of running a project with Docker is just amazing. When everything is configured properly, you can use just one command to start up project. All we need is “docker-compose.yml” file to define all the services we’re going to use and, in case we want to build a custom image, “Dockerfile” file with our steps. We also can use Docker on production using it in the Swarm mode.
Bonus: How to start a Django project using Docker
Create a Dockerfile for your Django app:
RUN apk update && apk --no-cache add \
RUN pip install --upgrade pip
RUN mkdir /app
ADD . /app/
RUN pip install Django==2.2.1
RUN pip install psycopg2==2.8.2
Create a docker-compose.yml file to group together our services:
Run these commands to create the initial project:
- docker-compose build – this will build the services in the docker-compose.yml file.
- docker-compose run django django-admin startproject mysite . – this will create the initial project. It’s just running `django-admin startproject mysite .` command in django container.
- docker-compose up – this command runs all of our services.
Learn more about Docker here to improve your development practices.
Now we can develop our project and do some awesome things. I hope my guide helps you choose the best options for setting up your Django development environment. If you have any questions, feel free to share them in the comments section.
These articles may also interest you:
- 10 Django packages you should know
- 6 best Django tutorials and books for advanced Python developers
- 6 expert tips for building better Django models