How to install django

How to install django

Documentation

How to install Django¶

This document will get you up and running with Django.

Install Python¶

Django is a Python web framework. See What Python version can I use with Django? for details.

Get the latest version of Python at https://www.python.org/downloads/ or with your operating system’s package manager.

Python on Windows

If you are just starting with Django and using Windows, you may find How to install Django on Windows useful.

Install Apache and mod_wsgi ¶

If you just want to experiment with Django, skip ahead to the next section; Django includes a lightweight web server you can use for testing, so you won’t need to set up Apache until you’re ready to deploy Django in production.

If you want to use Django on a production site, use Apache with mod_wsgi. mod_wsgi operates in one of two modes: embedded mode or daemon mode. In embedded mode, mod_wsgi is similar to mod_perl – it embeds Python within Apache and loads Python code into memory when the server starts. Code stays in memory throughout the life of an Apache process, which leads to significant performance gains over other server arrangements. In daemon mode, mod_wsgi spawns an independent daemon process that handles requests. The daemon process can run as a different user than the web server, possibly leading to improved security. The daemon process can be restarted without restarting the entire Apache web server, possibly making refreshing your codebase more seamless. Consult the mod_wsgi documentation to determine which mode is right for your setup. Make sure you have Apache installed with the mod_wsgi module activated. Django will work with any version of Apache that supports mod_wsgi.

See How to use Django with mod_wsgi for information on how to configure mod_wsgi once you have it installed.

If you can’t use mod_wsgi for some reason, fear not: Django supports many other deployment options. One is uWSGI ; it works very well with nginx. Additionally, Django follows the WSGI spec ( PEP 3333), which allows it to run on a variety of server platforms.

Get your database running¶

If you plan to use Django’s database API functionality, you’ll need to make sure a database server is running. Django supports many different database servers and is officially supported with PostgreSQL, MariaDB, MySQL, Oracle and SQLite.

If you are developing a small project or something you don’t plan to deploy in a production environment, SQLite is generally the best option as it doesn’t require running a separate server. However, SQLite has many differences from other databases, so if you are working on something substantial, it’s recommended to develop with the same database that you plan on using in production.

In addition to the officially supported databases, there are backends provided by 3rd parties that allow you to use other databases with Django.

In addition to a database backend, you’ll need to make sure your Python database bindings are installed.

If you’re using Django’s testing framework to test database queries, Django will need permission to create a test database.

Install the Django code¶

Installation instructions are slightly different depending on whether you’re installing a distribution-specific package, downloading the latest official release, or fetching the latest development version.

Installing an official release with pip ¶

This is the recommended way to install Django.

Install pip. The easiest is to use the standalone pip installer. If your distribution already has pip installed, you might need to update it if it’s outdated. If it’s outdated, you’ll know because installation won’t work.

After you’ve created and activated a virtual environment, enter the command:

Installing a distribution-specific package¶

Check the distribution specific notes to see if your platform/distribution provides official Django packages/installers. Distribution-provided packages will typically allow for automatic installation of dependencies and supported upgrade paths; however, these packages will rarely contain the latest release of Django.

Installing the development version¶

Tracking Django development

If you’d like to be able to update your Django code occasionally with the latest bug fixes and improvements, follow these instructions:

Make sure that you have Git installed and that you can run its commands from a shell. (Enter git help at a shell prompt to test this.)

Check out Django’s main development branch like so:

This will create a directory django in your current directory.

Make sure that the Python interpreter can load Django’s code. The most convenient way to do this is to use a virtual environment and pip. The contributing tutorial walks through how to create a virtual environment.

After setting up and activating the virtual environment, run the following command:

This will make Django’s code importable, and will also make the django-admin utility command available. In other words, you’re all set!

When you want to update your copy of the Django source code, run the command git pull from within the django directory. When you do this, Git will download any changes.

Documentation

FAQ: Installation¶

How do I get started?¶

What are Django’s prerequisites?¶

Django requires Python. See the table in the next question for the versions of Python that work with each version of Django. Other Python libraries may be required for some use cases, but you’ll receive an error about them as they’re needed.

For a development environment – if you just want to experiment with Django – you don’t need to have a separate web server installed or database server.

Django runs SQLite by default, which is included in Python installations. For a production environment, we recommend PostgreSQL; but we also officially support MariaDB, MySQL, SQLite, and Oracle. See Supported Databases for more information.

What Python version can I use with Django?¶

Django versionPython versions
2.23.5, 3.6, 3.7, 3.8 (added in 2.2.8), 3.9 (added in 2.2.17)
3.03.6, 3.7, 3.8, 3.9 (added in 3.0.11)
3.13.6, 3.7, 3.8, 3.9 (added in 3.1.3)
3.23.6, 3.7, 3.8, 3.9, 3.10 (added in 3.2.9)
4.03.8, 3.9, 3.10

For each version of Python, only the latest micro release (A.B.C) is officially supported. You can find the latest micro version for each series on the Python download page.

Typically, we will support a Python version up to and including the first Django LTS release whose security support ends after security support for that version of Python ends. For example, Python 3.3 security support ended September 2017 and Django 1.8 LTS security support ended April 2018. Therefore Django 1.8 is the last version to support Python 3.3.

What Python version should I use with Django?¶

Since newer versions of Python are often faster, have more features, and are better supported, the latest version of Python 3 is recommended.

You don’t lose anything in Django by using an older release, but you don’t take advantage of the improvements and optimizations in newer Python releases. Third-party applications for use with Django are free to set their own version requirements.

Should I use the stable version or development version?¶

Generally, if you’re using code in production, you should be using a stable release. The Django project publishes a full stable release every nine months or so, with bugfix updates in between. These stable releases contain the API that is covered by our backwards compatibility guarantees; if you write code against stable releases, you shouldn’t have any problems upgrading when the next official version is released.

Documentation

How to install Django¶

This document will get you up and running with Django.

Install Python¶

Get the latest version of Python at https://www.python.org/downloads/ or with your operating system’s package manager.

Django on Jython

Jython (a Python implementation for the Java platform) is not compatible with Python 3, so Django ≥ 2.0 cannot run on Jython.

Python on Windows

If you are just starting with Django and using Windows, you may find Comment installer Django avec Windows useful.

Install Apache and mod_wsgi ¶

If you just want to experiment with Django, skip ahead to the next section; Django includes a lightweight web server you can use for testing, so you won’t need to set up Apache until you’re ready to deploy Django in production.

If you want to use Django on a production site, use Apache with mod_wsgi. mod_wsgi operates in one of two modes: embedded mode or daemon mode. In embedded mode, mod_wsgi is similar to mod_perl – it embeds Python within Apache and loads Python code into memory when the server starts. Code stays in memory throughout the life of an Apache process, which leads to significant performance gains over other server arrangements. In daemon mode, mod_wsgi spawns an independent daemon process that handles requests. The daemon process can run as a different user than the Web server, possibly leading to improved security. The daemon process can be restarted without restarting the entire Apache Web server, possibly making refreshing your codebase more seamless. Consult the mod_wsgi documentation to determine which mode is right for your setup. Make sure you have Apache installed with the mod_wsgi module activated. Django will work with any version of Apache that supports mod_wsgi.

See How to use Django with mod_wsgi for information on how to configure mod_wsgi once you have it installed.

If you can’t use mod_wsgi for some reason, fear not: Django supports many other deployment options. One is uWSGI ; it works very well with nginx. Additionally, Django follows the WSGI spec ( PEP 3333), which allows it to run on a variety of server platforms.

Get your database running¶

If you plan to use Django’s database API functionality, you’ll need to make sure a database server is running. Django supports many different database servers and is officially supported with PostgreSQL, MySQL, Oracle and SQLite.

If you are developing a simple project or something you don’t plan to deploy in a production environment, SQLite is generally the simplest option as it doesn’t require running a separate server. However, SQLite has many differences from other databases, so if you are working on something substantial, it’s recommended to develop with the same database that you plan on using in production.

In addition to the officially supported databases, there are backends provided by 3rd parties that allow you to use other databases with Django.

In addition to a database backend, you’ll need to make sure your Python database bindings are installed.

If you’re using Django’s testing framework to test database queries, Django will need permission to create a test database.

Install the Django code¶

Installation instructions are slightly different depending on whether you’re installing a distribution-specific package, downloading the latest official release, or fetching the latest development version.

It’s easy, no matter which way you choose.

Installing an official release with pip ¶

This is the recommended way to install Django.

Install pip. The easiest is to use the standalone pip installer. If your distribution already has pip installed, you might need to update it if it’s outdated. If it’s outdated, you’ll know because installation won’t work.

Take a look at virtualenv and virtualenvwrapper. These tools provide isolated Python environments, which are more practical than installing packages systemwide. They also allow installing packages without administrator privileges. The contributing tutorial walks through how to create a virtualenv.

After you’ve created and activated a virtual environment, enter the command:

Installing a distribution-specific package¶

Check the distribution specific notes to see if your platform/distribution provides official Django packages/installers. Distribution-provided packages will typically allow for automatic installation of dependencies and easy upgrade paths; however, these packages will rarely contain the latest release of Django.

Installing the development version¶

Tracking Django development

If you’d like to be able to update your Django code occasionally with the latest bug fixes and improvements, follow these instructions:

Make sure that you have Git installed and that you can run its commands from a shell. (Enter git help at a shell prompt to test this.)

Check out Django’s main development branch like so:

This will create a directory django in your current directory.

Make sure that the Python interpreter can load Django’s code. The most convenient way to do this is to use virtualenv, virtualenvwrapper, and pip. The contributing tutorial walks through how to create a virtualenv.

After setting up and activating the virtualenv, run the following command:

This will make Django’s code importable, and will also make the django-admin utility command available. In other words, you’re all set!

When you want to update your copy of the Django source code, just run the command git pull from within the django directory. When you do this, Git will automatically download any changes.

How To Install Django

Django is a full stack open source web development framework written in Python that encourages rapid development and clean, pragmatic design. Since it’s release in 2003 Django has proven to be one of the most efficient modern web frameworks. Over the years Django and Python are on an unstoppable train of success. If you are planning to begin your journey as a web developer it’s the best MVC framework to start with. Read more about the origins of Django read: Django – Web Framework For Perfectionists.

In this article, we will go through the Installation process of Django.

Installing Django

As said, Django is a web framework written in Python, In order to install it first, you need to Install Python in your system. To check whether or not you have Python installed in your machine run this on your terminal.

Expected Output:

The version may vary until this returns the version of a Python release without any error, you are good to go. If this returns an error, then you have to install Python first.

Using Python 3.x+ is highly advised because Django 2.0+ is strictly for Python 3

After Python Installation we need to install virtualenv (Optional Prerequisite), this is not a dependency of Django, but it is advised to create separate virtual environments for different projects. By using virtual environments, applications can run in their own ‘sandbox’ in isolation of other Python applications.

To know more about the virtual environment and their installation procedure read: How To A Create Virtual Environment for Python

Once we have Python and virtual environment are in place we can proceed to create virtual environments for Django Installation this is not necessary but is recommended.

Creating Virtual Environment for Django

For Windows

For Unix and Mac

Now your terminal should be prefixed with django, if not then go through the virtual environment guide again.

Once the virtual environment is activated, we can finally proceed to Install Django. We will use Pip package manager to install Django.

This will install the latest version of Django in our environment. keep patience It may take some time depending on your internet connection.

To install a specific version of Django you can specify it as follows.

Verifying Django Installation

To verify the Django installation or to know the version of Django installed in your system execute this is terminal.

This should return an official Django release version.

Now that installation is done, you may deactivate the environment.

How to install django. Смотреть фото How to install django. Смотреть картинку How to install django. Картинка про How to install django. Фото How to install django

How to install django. Смотреть фото How to install django. Смотреть картинку How to install django. Картинка про How to install django. Фото How to install django

Abhijeet is a full-stack software developer from India with a strong focus on backend and system design. He is driven by the need to create impactful solutions that add value to the internet in any way possible.

Django installation

Note If you’re using a Chromebook, skip this chapter and make sure you follow the Chromebook Setup instructions.

Note If you already worked through the installation steps then you’ve already done this – you can go straight to the next chapter!

Part of this section is based on tutorials by Geek Girls Carrots (https://github.com/ggcarrots/django-carrots).

Part of this section is based on the django-marcador tutorial licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. The django-marcador tutorial is copyrighted by Markus Zapke-Gründemann et al.

Virtual environment

Before we install Django we will get you to install an extremely useful tool to help keep your coding environment tidy on your computer. It’s possible to skip this step, but it’s highly recommended. Starting with the best possible setup will save you a lot of trouble in the future!

So, let’s create a virtual environment (also called a virtualenv). Virtualenv will isolate your Python/Django setup on a per-project basis. This means that any changes you make to one website won’t affect any others you’re also developing. Neat, right?

All you need to do is find a directory in which you want to create the virtualenv ; your home directory, for example. On Windows, it might look like C:\Users\Name\ (where Name is the name of your login).

For this tutorial we will be using a new directory djangogirls from your home directory:

NOTE: On some versions of Debian/Ubuntu you may receive the following error:

In this case, follow the instructions above and install the python3-venv package:

NOTE: On some versions of Debian/Ubuntu initiating the virtual environment like this currently gives the following error:

To get around this, use the virtualenv command instead.

NOTE: If you get an error like

then instead run:

Working with virtualenv

The command above will create a directory called myvenv (or whatever name you chose) that contains our virtual environment (basically a bunch of directories and files).

Start your virtual environment by running:

NOTE: For users of the popular editor VS Code, which comes with an integrated terminal based off windows PowerShell, if you wish to stick with the integrated terminal, you may run the following command to activate your virtual environment:

The advantage is that you don’t have to switch between editor windows and command-line windows

Start your virtual environment by running:

Remember to replace myvenv with your chosen virtualenv name!

NOTE: If the command source is not available, try doing this instead:

OK, we have all important dependencies in place. We can finally install Django!

Installing Django

Now that you have your virtualenv started, you can install Django.

Installing packages with requirements

A requirements file keeps a list of dependencies to be installed using pip install :

First create a requirements.txt file inside of the djangogirls/ folder, using the code editor that you installed earlier. You do this by opening a new file in the code editor and then saving it as requirements.txt in the djangogirls/ folder. Your directory will look like this:

In your djangogirls/requirements.txt file you should add the following text:

If you get an error when calling pip on Windows, please check if your project pathname contains spaces, accents or special characters (for example, C:\Users\User Name\djangogirls ). If it does, please consider using another place without spaces, accents or special characters (suggestion: C:\djangogirls ). Create a new virtualenv in the new directory, then delete the old one and try the above command again. (Moving the virtualenv directory won’t work since virtualenv uses absolute paths.)

Your command line might freeze when you try to install Django. If this happens, instead of the above command use:

That’s it! You’re now (finally) ready to create a Django application!

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *