Bagaimana memasang Django¶
Dokumen ini akan membangunkan anda dan berjalan dengan Django.
Pasang Phyton¶
Django is a Python web framework. See Versi Phyton apa dapat Saya gunakan dengan Django? for details.
Dapatkan versi terakhir dari Python pada https://www.python.org/downloads/ atau dengan pengelola paket sistem operasi anda.
Phyton di Windows
Jika anda hanya memulai dengan Django dan menggunakan Windows, anda mungkin menemukan Bagaimana memasang Django pada WIndows berguna.
Pasang Apache dan mod_wsgi
¶
Jika anda hanya ingin melakukan percobaan dengan Django, lewati bagian selanjutnya; Django menyertakan peladen jaringan ringan anda dapat gunakan untuk percobaan, jadi anda tidak butuh menyetel Apache sampai anda siap menyebarkan Django dalam produksi.
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.
Lihat How to use Django with mod_wsgi 1 untuk informasi bagaimana mengkonfigurasi mode_wsgi sekali anda telah memasang itu.
Jika anda tidak dapat menggunakan mod_wsgi untuk beberapa alasan, jangan takut: Django mendukung banyak pilihan penyebaran lain. Satu adalah uWSGI; itu bekerja sangat baik dengan nginx. Selain itu, Django mengikuti spesifikasi WSGI (PEP 3333), yang mengizinkannya untuk berjalan pada seragam serambi peladen.
Dapatkan basisdata anda berjalan¶
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.
Sebagai tambahan ke basisdata didukung resmi, ada backends provided by 3rd parties 1 yang mengizinkan anda menggunakan basisdata lain dengan Django.
To use another database other than SQLite, you'll need to make sure that the appropriate Python database bindings are installed:
If you're using PostgreSQL, you'll need the psycopg or 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.Jika anda sedang menggunakan SQLite anda mungkin ingin membaca SQLite backend notes 1.
If you're using Oracle, you'll need to install oracledb, but please read the notes for the Oracle backend for details regarding supported versions of both Oracle and
oracledb
.Jika anda sedang menggunakan backend pihak ke3 tidak resmi, harap konsultasikan dokumentasi disediakan untuk persyaratan tambahan apapun.
And ensure that the following keys in the 'default'
item of the
DATABASES
dictionary match your database connection settings:
ENGINE
-- Salah satu'django.db.backends.sqlite3'
,'django.db.backends.postgresql'
,'django.db.backends.mysql'
, atau'django.db.backends.oracle'
. Backend lainnya adalah juga tersedia.NAME
-- The name of your database. If you’re using SQLite, the database will be a file on your computer. In that case,NAME
should be the full absolute path, including the filename of that file. You don’t need to create anything beforehand; the database file will be created automatically when needed. The default value,BASE_DIR / 'db.sqlite3'
, will store the file in your project directory.
Untuk basis data selain SQLite.
Jika anda tidak menggunakan SQlite sebagai basisdata anda, pengaturan tambahan seperti USER
, PASSWORD
, dan HOST
harus ditambahkan. Untuk lebih rinci, lihat acuan dukumentasi untuk DATABASES
.
Also, make sure that you've created the database by this point. Do that
with "CREATE DATABASE database_name;
" within your database's
interactive prompt.
Jika anda berencana untuk menggunakan perintah manage.py migrate
Django untuk secara otomatis membuat tabel basis data untuk model anda (setelah pertama memasang Django dan membuat proyek), anda harus memastikan bahwa Django memiliki izin untuk membuat dan mengubah tabel di database yang anda gunakan; jika anda berencana untuk membuat tabel secara manual, anda dapat memberikan izin Django SELECT
, INSERT
, UPDATE
dan DELETE
. Setelah membuat pengguna basis data dengan izin ini, anda akan menentukan rinciannya di berkas pengaturan proyek anda , lihat DATABASES
untuk rinciannya.
Jika anda sedang menggunakan testing framework1 Django untuk mencoba permintaan basisdata, Django akan butuh perizinan untuk membuat basisdata percobaan.
Pasang kode Django¶
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.
Memasang terbitan resmi dengan pip
¶
Ini adalah cara yang dianjurkan untuk memasang Django.
Pasang pip. Paling mudah adalah menggunakan standalone pip installer. Jika penyaluran anda sudah mempunyai
pip
terpasang, anda mungkin butuh memperbaharui jika itu sudah usang. Jika itu sudah usang, anda akan tahu karena pemasangan tidak akan bekerja.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
...\> py -m pip install Django
Memasang paket penyebaran-tertentu¶
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.
Memasang versi pengembangan¶
Melacak pengembangan Django
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:
Pastikan anda mempunyai Git terpasang dan anda dapat menjalankan perintah nya dari shell. (masukkan
git help
pada shell prompt untuk mencoba ini.)Periksa cabang pengembangan Django seperti itu:
$ git clone https://github.com/django/django.git
...\> git clone https://github.com/django/django.git
Ini akan membuat sebuah direktori
django
dalam direktori anda saat ini.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/
...\> 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.