tutorial08.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. =====================================
  2. Writing your first Django app, part 8
  3. =====================================
  4. This tutorial begins where :doc:`Tutorial 7 </intro/tutorial07>` left off. We've
  5. built our web-poll application and will now look at third-party packages. One of
  6. Django's strengths is the rich ecosystem of third-party packages. They're
  7. community developed packages that can be used to quickly improve the feature set
  8. of an application.
  9. This tutorial will show how to add `Django Debug Toolbar
  10. <https://django-debug-toolbar.readthedocs.io>`_, a commonly used third-party
  11. package. The Django Debug Toolbar has ranked in the top three most used
  12. third-party packages in the Django Developers Survey in recent years.
  13. .. admonition:: Where to get help:
  14. If you're having trouble going through this tutorial, please head over to
  15. the :doc:`Getting Help</faq/help>` section of the FAQ.
  16. Installing Django Debug Toolbar
  17. ===============================
  18. Django Debug Toolbar is a useful tool for debugging Django web applications.
  19. It's a third-party package maintained by the `Jazzband
  20. <https://jazzband.co>`_ organization. The toolbar helps you understand how your
  21. application functions and to identify problems. It does so by providing panels
  22. that provide debug information about the current request and response.
  23. To install a third-party application like the toolbar, you need to install
  24. the package by running the below command within an activated virtual
  25. environment. This is similar to our earlier step to :ref:`install Django
  26. <installing-official-release>`.
  27. .. console::
  28. $ python -m pip install django-debug-toolbar
  29. Third-party packages that integrate with Django need some post-installation
  30. setup to integrate them with your project. Often you will need to add the
  31. package's Django app to your :setting:`INSTALLED_APPS` setting. Some packages
  32. need other changes, like additions to your URLconf (``urls.py``).
  33. Django Debug Toolbar requires several setup steps. Follow them in `its
  34. installation guide
  35. <https://django-debug-toolbar.readthedocs.io/en/latest/installation.html>`_.
  36. The steps are not duplicated in this tutorial, because as a third-party
  37. package, it may change separately to Django's schedule.
  38. Once installed, you should be able to see the DjDT "handle" on the right side
  39. of the browser window when you refresh the polls application. Click it to open
  40. the debug toolbar and use the tools in each panel. See the `panels
  41. documentation page
  42. <https://django-debug-toolbar.readthedocs.io/en/latest/panels.html>`__ for more
  43. information on what the panels show.
  44. Getting help from others
  45. ========================
  46. At some point you will run into a problem, for example the
  47. toolbar may not render. When this happens and you're unable to
  48. resolve the issue yourself, there are options available to you.
  49. #. If the problem is with a specific package, check if there's a
  50. troubleshooting of FAQ in the package's documentation. For example the
  51. Django Debug Toolbar has a `Tips section
  52. <https://django-debug-toolbar.readthedocs.io/en/latest/tips.html>`_ that
  53. outlines troubleshooting options.
  54. #. Search for similar issues on the package's issue tracker. Django Debug
  55. Toolbar’s is `on GitHub <https://github.com/jazzband/django-debug-toolbar/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc>`_.
  56. #. Consult the `Django Forum <https://forum.djangoproject.com/>`_.
  57. #. Join the `Django Discord server <https://discord.gg/xcRH6mN4fa>`_.
  58. #. Join the #Django IRC channel on `Libera.chat <https://libera.chat/>`_.
  59. Installing other third-party packages
  60. =====================================
  61. There are many more third-party packages, which you can find using the
  62. fantastic Django resource, `Django Packages <https://djangopackages.org/>`_.
  63. It can be difficult to know what third-party packages you should use. This
  64. depends on your needs and goals. Sometimes it's fine to use a package that's
  65. in its alpha state. Other times, you need to know it's production ready.
  66. `Adam Johnson has a blog post
  67. <https://adamj.eu/tech/2021/11/04/the-well-maintained-test/>`_ that outlines
  68. a set of characteristics that qualifies a package as "well maintained".
  69. Django Packages shows data for some of these characteristics, such as when the
  70. package was last updated.
  71. As Adam points out in his post, when the answer to one of the questions is
  72. "no", that's an opportunity to contribute.
  73. What's next?
  74. ============
  75. The beginner tutorial ends here. In the meantime, you might want to check out
  76. some pointers on :doc:`where to go from here </intro/whatsnext>`.
  77. If you are familiar with Python packaging and interested in learning how to
  78. turn polls into a "reusable app", check out :doc:`Advanced tutorial: How to
  79. write reusable apps</intro/reusable-apps>`.