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 browse to ``http://localhost:8000/admin/``.
  40. Click it to open the debug toolbar and use the tools in each panel. See the
  41. `panels documentation page`__ for more information on what the panels show.
  42. __ https://django-debug-toolbar.readthedocs.io/en/latest/panels.html
  43. Getting help from others
  44. ========================
  45. At some point you will run into a problem, for example the
  46. toolbar may not render. When this happens and you're unable to
  47. resolve the issue yourself, there are options available to you.
  48. #. If the problem is with a specific package, check if there's a
  49. troubleshooting of FAQ in the package's documentation. For example the
  50. Django Debug Toolbar has a `Tips section
  51. <https://django-debug-toolbar.readthedocs.io/en/latest/tips.html>`_ that
  52. outlines troubleshooting options.
  53. #. Search for similar issues on the package's issue tracker. Django Debug
  54. Toolbar’s is `on GitHub <https://github.com/jazzband/django-debug-toolbar/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc>`_.
  55. #. Consult the `Django Forum <https://forum.djangoproject.com/>`_.
  56. #. Join the `Django Discord server <https://discord.gg/xcRH6mN4fa>`_.
  57. #. Join the #Django IRC channel on `Libera.chat <https://libera.chat/>`_.
  58. Installing other third-party packages
  59. =====================================
  60. There are many more third-party packages, which you can find using the
  61. fantastic Django resource, `Django Packages <https://djangopackages.org/>`_.
  62. It can be difficult to know what third-party packages you should use. This
  63. depends on your needs and goals. Sometimes it's fine to use a package that's
  64. in its alpha state. Other times, you need to know it's production ready.
  65. `Adam Johnson has a blog post
  66. <https://adamj.eu/tech/2021/11/04/the-well-maintained-test/>`_ that outlines
  67. a set of characteristics that qualifies a package as "well maintained".
  68. Django Packages shows data for some of these characteristics, such as when the
  69. package was last updated.
  70. As Adam points out in his post, when the answer to one of the questions is
  71. "no", that's an opportunity to contribute.
  72. What's next?
  73. ============
  74. The beginner tutorial ends here. In the meantime, you might want to check out
  75. some pointers on :doc:`where to go from here </intro/whatsnext>`.
  76. If you are familiar with Python packaging and interested in learning how to
  77. turn polls into a "reusable app", check out :doc:`Advanced tutorial: How to
  78. write reusable apps</intro/reusable-apps>`.