install.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. =====================
  2. How to install Django
  3. =====================
  4. This document will get you up and running with Django.
  5. Install Python
  6. ==============
  7. Django is a Python web framework. See :ref:`faq-python-version-support` for
  8. details.
  9. Get the latest version of Python at https://www.python.org/downloads/ or with
  10. your operating system's package manager.
  11. .. admonition:: Python on Windows
  12. If you are just starting with Django and using Windows, you may find
  13. :doc:`/howto/windows` useful.
  14. Install Apache and ``mod_wsgi``
  15. ===============================
  16. If you just want to experiment with Django, skip ahead to the next
  17. section; Django includes a lightweight web server you can use for
  18. testing, so you won't need to set up Apache until you're ready to
  19. deploy Django in production.
  20. If you want to use Django on a production site, use `Apache`_ with
  21. `mod_wsgi`_. mod_wsgi operates in one of two modes: embedded
  22. mode or daemon mode. In embedded mode, mod_wsgi is similar to
  23. mod_perl -- it embeds Python within Apache and loads Python code into
  24. memory when the server starts. Code stays in memory throughout the
  25. life of an Apache process, which leads to significant performance
  26. gains over other server arrangements. In daemon mode, mod_wsgi spawns
  27. an independent daemon process that handles requests. The daemon
  28. process can run as a different user than the web server, possibly
  29. leading to improved security. The daemon process can be restarted
  30. without restarting the entire Apache web server, possibly making
  31. refreshing your codebase more seamless. Consult the mod_wsgi
  32. documentation to determine which mode is right for your setup. Make
  33. sure you have Apache installed with the mod_wsgi module activated.
  34. Django will work with any version of Apache that supports mod_wsgi.
  35. See :doc:`How to use Django with mod_wsgi </howto/deployment/wsgi/modwsgi>`
  36. for information on how to configure mod_wsgi once you have it
  37. installed.
  38. If you can't use mod_wsgi for some reason, fear not: Django supports many other
  39. deployment options. One is :doc:`uWSGI </howto/deployment/wsgi/uwsgi>`; it works
  40. very well with `nginx`_. Additionally, Django follows the WSGI spec
  41. (:pep:`3333`), which allows it to run on a variety of server platforms.
  42. .. _Apache: https://httpd.apache.org/
  43. .. _nginx: https://nginx.org/
  44. .. _mod_wsgi: https://modwsgi.readthedocs.io/en/develop/
  45. .. _database-installation:
  46. Get your database running
  47. =========================
  48. If you plan to use Django's database API functionality, you'll need to make
  49. sure a database server is running. Django supports many different database
  50. servers and is officially supported with PostgreSQL_, MariaDB_, MySQL_, Oracle_
  51. and SQLite_.
  52. If you are developing a small project or something you don't plan to deploy in
  53. a production environment, SQLite is generally the best option as it doesn't
  54. require running a separate server. However, SQLite has many differences from
  55. other databases, so if you are working on something substantial, it's
  56. recommended to develop with the same database that you plan on using in
  57. production.
  58. In addition to the officially supported databases, there are :ref:`backends
  59. provided by 3rd parties <third-party-notes>` that allow you to use other
  60. databases with Django.
  61. To use another database other than SQLite, you'll need to make sure that the
  62. appropriate Python database bindings are installed:
  63. * If you're using PostgreSQL, you'll need the `psycopg`_ or `psycopg2`_
  64. package. Refer to the :ref:`PostgreSQL notes <postgresql-notes>` for further
  65. details.
  66. * If you're using MySQL or MariaDB, you'll need a :ref:`DB API driver
  67. <mysql-db-api-drivers>` like ``mysqlclient``. See :ref:`notes for the MySQL
  68. backend <mysql-notes>` for details.
  69. * If you're using SQLite you might want to read the :ref:`SQLite backend notes
  70. <sqlite-notes>`.
  71. * If you're using Oracle, you'll need to install oracledb_, but please read the
  72. :ref:`notes for the Oracle backend <oracle-notes>` for details regarding
  73. supported versions of both Oracle and ``oracledb``.
  74. * If you're using an unofficial 3rd party backend, please consult the
  75. documentation provided for any additional requirements.
  76. And ensure that the following keys in the ``'default'`` item of the
  77. :setting:`DATABASES` dictionary match your database connection settings:
  78. * :setting:`ENGINE <DATABASE-ENGINE>` -- Either
  79. ``'django.db.backends.sqlite3'``,
  80. ``'django.db.backends.postgresql'``,
  81. ``'django.db.backends.mysql'``, or
  82. ``'django.db.backends.oracle'``. Other backends are :ref:`also available
  83. <third-party-notes>`.
  84. * :setting:`NAME` -- The name of your database. If you’re using SQLite, the
  85. database will be a file on your computer. In that case, ``NAME`` should be
  86. the full absolute path, including the filename of that file. You don’t need
  87. to create anything beforehand; the database file will be created
  88. automatically when needed. The default value, ``BASE_DIR / 'db.sqlite3'``,
  89. will store the file in your project directory.
  90. .. admonition:: For databases other than SQLite
  91. If you are not using SQLite as your database, additional settings such as
  92. :setting:`USER`, :setting:`PASSWORD`, and :setting:`HOST` must be added.
  93. For more details, see the reference documentation for :setting:`DATABASES`.
  94. Also, make sure that you've created the database by this point. Do that
  95. with "``CREATE DATABASE database_name;``" within your database's
  96. interactive prompt.
  97. If you plan to use Django's ``manage.py migrate`` command to automatically
  98. create database tables for your models (after first installing Django and
  99. creating a project), you'll need to ensure that Django has permission to create
  100. and alter tables in the database you're using; if you plan to manually create
  101. the tables, you can grant Django ``SELECT``, ``INSERT``, ``UPDATE`` and
  102. ``DELETE`` permissions. After creating a database user with these permissions,
  103. you'll specify the details in your project's settings file, see
  104. :setting:`DATABASES` for details.
  105. If you're using Django's :doc:`testing framework</topics/testing/index>` to test
  106. database queries, Django will need permission to create a test database.
  107. .. _PostgreSQL: https://www.postgresql.org/
  108. .. _MariaDB: https://mariadb.org/
  109. .. _MySQL: https://www.mysql.com/
  110. .. _psycopg: https://www.psycopg.org/psycopg3/
  111. .. _psycopg2: https://www.psycopg.org/
  112. .. _SQLite: https://www.sqlite.org/
  113. .. _oracledb: https://oracle.github.io/python-oracledb/
  114. .. _Oracle: https://www.oracle.com/
  115. .. _install-django-code:
  116. Install the Django code
  117. =======================
  118. Installation instructions are slightly different depending on whether you're
  119. installing a distribution-specific package, downloading the latest official
  120. release, or fetching the latest development version.
  121. .. _installing-official-release:
  122. Installing an official release with ``pip``
  123. -------------------------------------------
  124. This is the recommended way to install Django.
  125. #. Install pip_. The easiest is to use the `standalone pip installer`_. If your
  126. distribution already has ``pip`` installed, you might need to update it if
  127. it's outdated. If it's outdated, you'll know because installation won't
  128. work.
  129. #. Take a look at :doc:`venv <python:tutorial/venv>`. This tool provides
  130. isolated Python environments, which are more practical than installing
  131. packages systemwide. It also allows installing packages without
  132. administrator privileges. The :doc:`contributing tutorial
  133. </intro/contributing>` walks through how to create a virtual environment.
  134. #. After you've created and activated a virtual environment, enter the command:
  135. .. console::
  136. $ python -m pip install Django
  137. .. _pip: https://pip.pypa.io/
  138. .. _standalone pip installer: https://pip.pypa.io/en/latest/installation/
  139. .. _installing-distribution-package:
  140. Installing a distribution-specific package
  141. ------------------------------------------
  142. Check the :doc:`distribution specific notes </misc/distributions>` to see if
  143. your platform/distribution provides official Django packages/installers.
  144. Distribution-provided packages will typically allow for automatic installation
  145. of dependencies and supported upgrade paths; however, these packages will rarely
  146. contain the latest release of Django.
  147. .. _installing-development-version:
  148. Installing the development version
  149. ----------------------------------
  150. .. admonition:: Tracking Django development
  151. If you decide to use the latest development version of Django,
  152. you'll want to pay close attention to `the development timeline`_,
  153. and you'll want to keep an eye on the :ref:`release notes for the
  154. upcoming release <development_release_notes>`. This will help you stay
  155. on top of any new features you might want to use, as well as any changes
  156. you'll need to make to your code when updating your copy of Django.
  157. (For stable releases, any necessary changes are documented in the
  158. release notes.)
  159. .. _the development timeline: https://code.djangoproject.com/timeline
  160. If you'd like to be able to update your Django code occasionally with the
  161. latest bug fixes and improvements, follow these instructions:
  162. #. Make sure that you have Git_ installed and that you can run its commands
  163. from a shell. (Enter ``git help`` at a shell prompt to test this.)
  164. #. Check out Django's main development branch like so:
  165. .. console::
  166. $ git clone https://github.com/django/django.git
  167. This will create a directory ``django`` in your current directory.
  168. #. Make sure that the Python interpreter can load Django's code. The most
  169. convenient way to do this is to use a virtual environment and pip_. The
  170. :doc:`contributing tutorial </intro/contributing>` walks through how to
  171. create a virtual environment.
  172. #. After setting up and activating the virtual environment, run the following
  173. command:
  174. .. console::
  175. $ python -m pip install -e django/
  176. This will make Django's code importable, and will also make the
  177. ``django-admin`` utility command available. In other words, you're all
  178. set!
  179. When you want to update your copy of the Django source code, run the command
  180. ``git pull`` from within the ``django`` directory. When you do this, Git will
  181. download any changes.
  182. .. _Git: https://git-scm.com/