• 5.0
  • dev
  • Wersja dokumentacji: 4.2

Pisanie pierwszej aplikacji Django, część 8.

Ten tutorial rozpoczyna się w miejscu, w którym zakończył się tutorial 7. Zbudowaliśmy naszą aplikację web-poll i teraz przyjrzymy się zewnętrznym pakietom. Jedną z mocnych stron Django jest bogaty ekosystem zewnętrznych pakietów. Są to opracowane przez społeczność pakiety, które mogą być użyte do szybkiego ulepszenia zestawu funkcji aplikacji.

Ten tutorial pokaże jak dodać Django Debug Toolbar, powszechnie używany zewnętrzny pakiet. Django Debug Toolbar znalazł się w pierwszej trójce najczęściej używanych zewnętrznych pakietów w Django Developers Survey w ostatnich latach.

Gdzie szukać pomocy:

Jeśli masz trudności w przejściu tego tutorialu, przejdź do sekcji Uzyskiwanie pomocy często zadawanych pytań.

Installing Django Debug Toolbar

Django Debug Toolbar is a useful tool for debugging Django web applications. It’s a third-party package maintained by the Jazzband organization. The toolbar helps you understand how your application functions and to identify problems. It does so by providing panels that provide debug information about the current request and response.

To install a third-party application like the toolbar, you need to install the package by running the below command within an activated virtual environment. This is similar to our earlier step to install Django.

$ python -m pip install django-debug-toolbar
...\> py -m pip install django-debug-toolbar

Third-party packages that integrate with Django need some post-installation setup to integrate them with your project. Often you will need to add the package’s Django app to your INSTALLED_APPS setting. Some packages need other changes, like additions to your URLconf (urls.py).

Django Debug Toolbar requires several setup steps. Follow them in its installation guide. The steps are not duplicated in this tutorial, because as a third-party package, it may change separately to Django’s schedule.

Once installed, you should be able to see the DjDT „handle” on the right side of the browser window when you refresh the polls application. Click it to open the debug toolbar and use the tools in each panel. See the panels documentation page for more information on what the panels show.

Getting help from others

At some point you will run into a problem, for example the toolbar may not render. When this happens and you’re unable to resolve the issue yourself, there are options available to you.

  1. If the problem is with a specific package, check if there’s a troubleshooting of FAQ in the package’s documentation. For example the Django Debug Toolbar has a Tips section that outlines troubleshooting options.
  2. Search for similar issues on the package’s issue tracker. Django Debug Toolbar’s is on GitHub.
  3. Consult the Django Forum.
  4. Join the Django Discord server.
  5. Join the #Django IRC channel on Libera.chat.

Installing other third-party packages

There are many more third-party packages, which you can find using the fantastic Django resource, Django Packages.

It can be difficult to know what third-party packages you should use. This depends on your needs and goals. Sometimes it’s fine to use a package that’s in its alpha state. Other times, you need to know it’s production ready. Adam Johnson has a blog post that outlines a set of characteristics that qualifies a package as „well maintained”. Django Packages shows data for some of these characteristics, such as when the package was last updated.

As Adam points out in his post, when the answer to one of the questions is „no”, that’s an opportunity to contribute.

Co dalej?

Tutorial dla początkujących kończy się tutaj. W międzyczasie możesz chcieć sprawdzić niektóre z kierunków wskazanych w gdzie iść dalej.

Jeśli jesteś zaznajomiony z pakietowaniem w Pythonie i zainteresowany jak uczynić ankiety „aplikacją reusable”, sprawdź Zaawansowany tutorial: Jak pisać aplikacje do ponownego wykorzystania.

Back to Top