How to install Django-Install Python Django | Django 安装指南【官方版】
How to install Django¶
This document will get you up and running with Django.
Install Python——Linux and MacOS
Django is a Python web framework. See What Python version can I use with Django? for details.
Get the latest version of Python at Download Python | Python.org 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 PostgreSQL, you’ll need the psycopg2 package. Refer to the PostgreSQL notes for further details.
- If you’re using MySQL or MariaDB, you’ll need a DB API driver like
mysqlclient
. See notes for the MySQL backend for details. - If you’re using SQLite you might want to read the SQLite backend notes.
- If you’re using Oracle, you’ll need a copy of cx_Oracle, but please read the notes for the Oracle backend for details regarding supported versions of both Oracle and
cx_Oracle
. - If you’re using an unofficial 3rd party backend, please consult the documentation provided for any additional requirements.
If you plan to use Django’s manage.py migrate
command to automatically create database tables for your models (after first installing Django and creating a project), you’ll need to ensure that Django has permission to create and alter tables in the database you’re using; if you plan to manually create the tables, you can grant Django SELECT
, INSERT
, UPDATE
and DELETE
permissions. After creating a database user with these permissions, you’ll specify the details in your project’s settings file, see DATABASES for details.
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.Take a look at venv. This tool provides isolated Python environments, which are more practical than installing packages systemwide. It also allows installing packages without administrator privileges. The contributing tutorial walks through how to create a virtual environment.
After you’ve created and activated a virtual environment, enter the command:
/
$
python -m pip install Django
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 decide to use the latest development version of Django, you’ll want to pay close attention to the development timeline, and you’ll want to keep an eye on the release notes for the upcoming release. This will help you stay on top of any new features you might want to use, as well as any changes you’ll need to make to your code when updating your copy of Django. (For stable releases, any necessary changes are documented in the release notes.)
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:
/
$
git clone https://github.com/django/django.git
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:
/
$
python -m pip install -e django/
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.
===================== 中文版指南===============
如何安装 Django ¶
本文档将帮助您启动并运行 Django。
安装 Python ¶
Django 是一个 Python 网络框架。请参阅我可以在 Django 中使用哪个 Python 版本?详情。
在https://www.python.org/downloads/或使用操作系统的包管理器获取最新版本的 Python 。
Windows 上的 Python
如果您刚开始使用 Django 并使用 Windows,您可能会发现如何在 Windows 上安装 Django很有用。
安装 Apache 和mod_wsgi
¶
如果你只是想试验一下 Django,请跳到下一节;Django 包含一个可用于测试的轻量级 Web 服务器,因此在您准备好在生产中部署 Django 之前,您无需设置 Apache。
如果您想在生产站点上使用 Django,请使用带有mod_wsgi的Apache. mod_wsgi 以两种模式之一运行:嵌入式模式或守护进程模式。在嵌入模式下,mod_wsgi 类似于 mod_perl——它将 Python 嵌入到 Apache 中,并在服务器启动时将 Python 代码加载到内存中。代码在 Apache 进程的整个生命周期中都保留在内存中,与其他服务器安排相比,这会带来显着的性能提升。在守护进程模式下,mod_wsgi 生成一个独立的守护进程来处理请求。守护进程可以作为与 Web 服务器不同的用户运行,这可能会提高安全性。守护进程可以在不重新启动整个 Apache Web 服务器的情况下重新启动,这可能使您的代码库的刷新更加无缝。请查阅 mod_wsgi 文档以确定哪种模式适合您的设置。确保您安装了 Apache 并激活了 mod_wsgi 模块。
有关安装 mod_wsgi 后如何配置它的信息,请参阅如何将 Django 与 mod_wsgi 一起使用。
如果由于某种原因不能使用 mod_wsgi,请不要担心:Django 支持许多其他部署选项。一是uWSGI;它与nginx配合得很好。此外,Django 遵循 WSGI 规范 (PEP 3333),这允许它在各种服务器平台上运行。
让你的数据库运行¶
如果您打算使用 Django 的数据库 API 功能,则需要确保数据库服务器正在运行。Django 支持许多不同的数据库服务器,并得到PostgreSQL、MariaDB、MySQL、Oracle和SQLite的正式支持。
如果您正在开发一个小型项目或不打算在生产环境中部署的东西,SQLite 通常是最佳选择,因为它不需要运行单独的服务器。但是,SQLite 与其他数据库有很多不同之处,因此如果您正在做一些实质性的工作,建议使用您计划在生产中使用的相同数据库进行开发。
除了官方支持的数据库之外,还有第三方提供的后端允许您在 Django 中使用其他数据库。
除了数据库后端之外,您还需要确保安装了 Python 数据库绑定。
- 如果您使用的是 PostgreSQL,则需要psycopg2包。有关详细信息,请参阅PostgreSQL 说明。
- 如果您使用 MySQL 或 MariaDB,则需要一个DB API 驱动程序,例如
mysqlclient
. 有关详细信息,请参阅MySQL 后端的注释。 - 如果您使用 SQLite,您可能需要阅读SQLite 后端说明。
- 如果您使用的是 Oracle,则需要一份cx_Oracle的副本,但请阅读Oracle 后端的说明,了解有关 Oracle 和
cx_Oracle
. - 如果您使用的是非官方的第 3 方后端,请查阅提供的文档以了解任何其他要求。
如果您打算使用 Django 的命令为您的模型自动创建数据库表(在首次安装 Django 并创建项目之后),您需要确保 Django 有权在您正在使用的数据库中创建和更改表;如果您计划手动创建表,您可以授予 Django 、和权限。创建具有这些权限的数据库用户后,您将在项目的设置文件中指定详细信息,请参阅详细信息。manage.py migrate
SELECT
INSERT
UPDATE
DELETE
DATABASES
如果您使用 Django 的测试框架来测试数据库查询,则 Django 将需要创建测试数据库的权限。
安装 Django 代码¶
根据您是安装特定于发行版的软件包、下载最新的官方版本还是获取最新的开发版本,安装说明会略有不同。
使用¶安装官方版本pip
这是安装 Django 的推荐方式。
安装点子。最简单的是使用独立的 pip 安装程序。如果您的发行版已经
pip
安装,如果它已经过时,您可能需要更新它。如果它已过时,您会知道,因为安装将无法正常工作。看看venv。该工具提供了隔离的 Python 环境,这比在系统范围内安装包更实用。它还允许在没有管理员权限的情况下安装软件包。贡献教程介绍了如何创建虚拟环境。
创建并激活虚拟环境后,输入命令:
/ $
python -m pip install Django
安装特定于发行版的包¶
检查发行版的具体说明,看看你的平台/发行版是否提供官方的 Django 包/安装程序。分发提供的软件包通常允许自动安装依赖项和支持的升级路径;然而,这些包很少会包含最新版本的 Django。
安装开发版本¶
跟踪 Django 开发
如果您决定使用 Django 的最新开发版本,您需要密切关注开发时间线,并密切关注即将发布的版本说明。这将帮助您掌握可能想要使用的任何新功能,以及在更新 Django 副本时需要对代码进行的任何更改。(对于稳定版本,任何必要的更改都记录在发行说明中。)
如果您希望能够偶尔使用最新的错误修复和改进来更新您的 Django 代码,请按照以下说明进行操作:
确保您已安装Git,并且您可以从 shell 运行它的命令。(在 shell 提示符下输入以测试它。)
git help
查看 Django 的主要开发分支,如下所示:
/ $
git clone https://github.com/django/django.git
django
这将在您的当前目录中创建一个目录。确保 Python 解释器可以加载 Django 的代码。最方便的方法是使用虚拟环境和pip。贡献教程介绍了如何创建虚拟环境。
设置并激活虚拟环境后,运行以下命令:
/ $
python -m pip install -e django/
这将使 Django 的代码可导入,并且还将使
django-admin
实用程序命令可用。换句话说,你已经准备好了!
如果要更新 Django 源代码的副本,请从目录中运行命令。执行此操作时,Git 将下载所有更改。git pull
django
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 Download Python | Python.org 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 PostgreSQL, you’ll need the psycopg2 package. Refer to the PostgreSQL notes for further details.
- If you’re using MySQL or MariaDB, you’ll need a DB API driver like
mysqlclient
. See notes for the MySQL backend for details. - If you’re using SQLite you might want to read the SQLite backend notes.
- If you’re using Oracle, you’ll need a copy of cx_Oracle, but please read the notes for the Oracle backend for details regarding supported versions of both Oracle and
cx_Oracle
. - If you’re using an unofficial 3rd party backend, please consult the documentation provided for any additional requirements.
If you plan to use Django’s manage.py migrate
command to automatically create database tables for your models (after first installing Django and creating a project), you’ll need to ensure that Django has permission to create and alter tables in the database you’re using; if you plan to manually create the tables, you can grant Django SELECT
, INSERT
, UPDATE
and DELETE
permissions. After creating a database user with these permissions, you’ll specify the details in your project’s settings file, see DATABASES for details.
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.Take a look at venv. This tool provides isolated Python environments, which are more practical than installing packages systemwide. It also allows installing packages without administrator privileges. The contributing tutorial walks through how to create a virtual environment.
After you’ve created and activated a virtual environment, enter the command:
/
...\> py -m pip install Django
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 decide to use the latest development version of Django, you’ll want to pay close attention to the development timeline, and you’ll want to keep an eye on the release notes for the upcoming release. This will help you stay on top of any new features you might want to use, as well as any changes you’ll need to make to your code when updating your copy of Django. (For stable releases, any necessary changes are documented in the release notes.)
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:
/
...\> git clone https://github.com/django/django.git
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:
/
...\> py -m pip install -e django\
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.
How to install Django-Install Python Django | Django 安装指南【官方版】的更多相关文章
- python web -- django
一. 安装 django $ pip install django (env)$ python >> import django >> django.VERSION >& ...
- [Django] Get started with Django -- Install python and virtualenv
Install python3 on MacOS: brew install python3 Come alone with python3, there are also some other to ...
- [Python] 利用Django进行Web开发系列(一)
1 写在前面 在没有接触互联网这个行业的时候,我就一直很好奇网站是怎么构建的.现在虽然从事互联网相关的工作,但是也一直没有接触过Web开发之类的东西,但是兴趣终归还是要有的,而且是需要自己动手去实践的 ...
- VIM for Python and Django Development
VIM for Python and Django Development VIM-PyDjango created by Programmer for Programmer who work on ...
- Python 之Django
1.安装Django(下载慢的时候用MaxVPN) pip3 install django 2.Django处理流程 新建project(mysite),执行dj(mysite),然后在console ...
- Window环境下Python和Django的安装
转载地址:http://blog.csdn.net/haoni123321/article/details/7593821 1.下载python,本文使用python-2.7.2.msi 2.下载dj ...
- Python和Django在Windows上的环境搭建
作为一个.NET程序员,真心不喜欢Python以及PHP这种松散的语法.有人说,程序员应该多学几门语言,本想学习Java,无奈感觉Java的语法太啰嗦了.很多人都推荐Python,说它的语法简洁,执行 ...
- 【Python】django安装
官方下载:https://www.djangoproject.com/download/ 报错 [root@test Django-]# python setup.py install Traceba ...
- Django是Python下的一款网络服务器框架
被解放的姜戈01 初试天涯 Django是Python下的一款网络服务器框架.Python下有许多款不同的框架.Django是重量级选手中最有代表性的一位.许多成功的网站和APP都基于Django ...
- Python 学习笔记13:Python + wsgi + django 配置。坑爹的python3和wsgi不兼容的解决
今人不见古时月,今月曾经照古人.生命是如此的美丽与短暂! 学习Python已经两个月了,Python的语法通过做简单的语法题和看Python语法介绍,有了初步的了解.但上班还是要做别的事情,所以感觉学 ...
随机推荐
- 接口自动化有多少case?覆盖率是多少?执行完需要多久?
case根据接口数量而定,比如两百个接口,大概有5000个用例,一个接口大概有25到30个用例,一个接口大概200ms左右响应时间 覆盖率能达到95%以上,有时候可以达到百分之百,所有接口自动化用例执 ...
- Java 包装类的使用(自动装箱+自动拆箱)+Vector
1 package com.bytezreo.ut; 2 3 import java.util.Scanner; 4 import java.util.Vector; 5 6 /** 7 * 8 * ...
- Spring5课堂笔记
Spring5 1..Spring 1.1.简介 Spring --> 春天,为开源软件带来了春天 2002,首次推出了Spring框架的雏形:interface21框架! Spring框架以i ...
- manjaro蓝牙链接不上或者连接上了没有声音
查看这些软件宝有没有安装上:sudo pacman -S bluez bluez-utils pulseaudio-bluetooth pavucontrol pulseaudio-alsa puls ...
- QT 使用QPixmap自定义光标 缩放图像模糊问题
QT中定义光标可以使用 Qt::CursorShape 预定义 的光标,也可以使用 QBitmap 和 QPixmap 自己绘制光标.QBitmap 只有黑白2色,QPixmap可以绘制彩色光标.使用 ...
- Windows 2012 R2 修复CredSSP 远程执行代码漏洞 CVE-2018-0886
本文基于window 2012 R2版本,各位参考下载自己版本对应的补丁包即可 说明 公司的安全性检查,需要修复服务器上的漏洞,其中有个漏洞是CVE-2018-0886,结果网上的资料和一番折腾,终于 ...
- ubuntu切换root到user
目前知道: 从root用户切回user用户有三种方法: 1.su user (user是你自己安装时候的用户名) 2.直接输入exit 3.ctrl+D组合键
- Spring Boot 实现各种参数校验(附项目源码)
本文会详细介绍Spring Validation各种场景下的最佳实践及其实现原理,死磕到底! 项目源码:spring-validation 一.简单使用 Java API规范(JSR303)定义了Be ...
- 🚀🚀🚀Elasticsearch 主副分片切换过程中对业务写入有影响吗
先说下结论,只要集群中的工作节点过半,有候选的master节点,挂掉的节点中不同时包含索引的主分片和副分片,那么ES是可以做到让业务无感知的进行主副分片切换的. 蓝胖子会先讲解下ES集群写入文档的原理 ...
- 为什么ASP.NET Core的路由处理器可以使用一个任意类型的Delegate
毫不夸张地说,路由是ASP.NET Core最为核心的部分.路由的本质就是注册一系列终结点(Endpoint),每个终结点可以视为"路由模式"和"请求处理器"的 ...