Django In Pycharm Community



Before we start, if you don`t know what is profiling read this Wikipedia article! In my opinion profiling should be a part of every development/build process! Whether the responsibility lies with QA or development. Python profiler are supported only in PyCharm Professional Edition. This article show you the possibilities for the community edition.

Preparation

  1. How to use python behave in PyCharm Community Edition behave is a tool for behavior-driven development (BDD). BDD support is available only in the PyCharm Professional Edition, not in the Community Edition (CE).
  2. PyCharm Community is free as well and intended for pure Python development. PyCharm Professional is paid, has everything the Community edition has and also is very well suited for Web and Scientific development with support for such frameworks as Django and Flask, Database and SQL, and scientific tools such as Jupyter.

Debugging a Containerized Django App in PyCharm Developing your Django app in Docker can be very convenient. You don't have to install extra services like Postgres, Nginx, and Redis, etc. On you own machine. It also makes it much easier for a new developer to quickly get up and running. PyCharm is the most popular IDE for Python, and includes great features such as excellent code completion and inspection with advanced debugger and support for web programming and various frameworks. PyCharm is created by Czech company, Jet brains which focusses on creating integrated development environment for various web development. One of the features of PyCharm is that it includes a support for Django. With the ability of including JavaScript features within PyCharm, it can be considered as the best IDE for Django. The basic steps for creating a Django project in PyCharm IDE are given below −.

  • PyCharm installed
  • Virtualenv or similar installed (optional)
  • PyCharm BashSupport Plugin installed

The easiest Profiler

With Unix/Linux time command you have allready a simple profiler! Time writes a message to standard output. Here you will find some information on Stackoverflow.

With BashSupport Plugin we can setup the “Run/Debug Configuration” like:

Better informations

But now we need better information. For this we use cProfile, cprofilev and snakeviz.

“Run/Debug Configuration” example

Now will store the results into a file

With snakeviz you can open the profile in browser:

The other option is to use cprofilev:

Even more information

If that was not enough,… we install some more libraries.

Install django in pycharm community edition

Now we need to change the example code. We add the decorator…

the line_profiler configuration

the memory_profiler

All configurations could now startet via the “Run” button. There are even more Profiler that you can use with similar PyCharm.

Introduction

There is a most important thing I want to remind before I start: to use the Python interpreter of remote server requires the professional version of PyCharm. The community version has no way to configure the remote Python interpreter. (If I make a mistake, please feel free to tell me.)

Fortunately, in addition to spending money to buy it, you can apply for a free professional version if you are a student and have a school email address. One application can be valid for one year.

You can go to the following website to apply: https://www.jetbrains.com/pycharm/download/#section=windows

If you want to know how to install PyCharm, maybe you can refer to this article: PyCharm Installation Tutorial, A famous Python IDE

Okay, let's start!

Pycharm

Configure remote interpreter settings

First, I build a new project of the example.

Select File => Settings to open the setting window. Of course you can also use the shortcut key Ctrl + Alt + s to open it.

After opening, select Project: 'YOUR_PROJECT_NAME' => Project Interpreter in the left bar.

Click the gear in the upper right corner and select Add button. The add Python interpreter window pops up:

Select SSH Interpreter.

Select New server configuration, and fill in the connection settings in sequence. After selecting, select Next.

Enter the password of the connection account, and then select Next again.

For the remote Python interpreter, you can use ssh command to connect to it first, and use the following command to confirm where the Python interpreter is.

Tests

Usually the path is approximately:

Above this is the path of my Python interpreter.

Install django in pycharm

Pycharm Professional Vs Community

It is not recommended to preset the location of the synchronization folder, but it is better to create it separately. The method to change the path is to click on the folder icon on the right of step 2 in the figure, and then select the folder on the right of Remote Path again to select the folder you want to synchronize remotely.

Select Finish to end the configuration of the remote interpreter.

Hint

Install Django In Pycharm Community Edition

If PyCharm does not feel smooth or a bit stuck during remote synchronization, it may be because its background has been detecting whether to synchronize all files in the current folder. You can go to Tools => Deployment => to turn off Automatic Upload. Maybe it will be smoother.

If there is no manual upload file to the remote synchronization folder under Deployment, you can enter Configuration for configuration.

Pycharm Django App

After configuring in order, there is probably no problem.

Pycharm Open Existing Django Project

Maybe you want to read: