tutorial08.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 :pypi:`Django Debug Toolbar
  10. <django-debug-toolbar>`, a commonly used third-party package. The Django Debug
  11. Toolbar has ranked in the top three most used third-party packages in the
  12. 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 that is maintained by the community organization
  20. `Django Commons <https://github.com/django-commons>`_. The toolbar helps you
  21. understand how your application functions and to identify problems. It does so
  22. by providing panels that provide debug information about the current request
  23. and response.
  24. To install a third-party application like the toolbar, you need to install
  25. the package by running the below command within an activated virtual
  26. environment. This is similar to our earlier step to :ref:`install Django
  27. <installing-official-release>`.
  28. .. console::
  29. $ python -m pip install django-debug-toolbar
  30. Third-party packages that integrate with Django need some post-installation
  31. setup to integrate them with your project. Often you will need to add the
  32. package's Django app to your :setting:`INSTALLED_APPS` setting. Some packages
  33. need other changes, like additions to your URLconf (``urls.py``).
  34. Django Debug Toolbar requires several setup steps. Follow them in `its
  35. installation guide
  36. <https://django-debug-toolbar.readthedocs.io/en/latest/installation.html>`_.
  37. The steps are not duplicated in this tutorial, because as a third-party
  38. package, it may change separately to Django's schedule.
  39. Once installed, you should be able to see the DjDT "handle" on the right side
  40. of the browser window when you browse to ``http://localhost:8000/admin/``.
  41. Click it to open the debug toolbar and use the tools in each panel. See the
  42. `panels documentation page`__ for more information on what the panels show.
  43. __ https://django-debug-toolbar.readthedocs.io/en/latest/panels.html
  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/django-commons/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>`.