Bagaimana memasang DjangoLink to this heading

Dokumen ini akan membangunkan anda dan berjalan dengan Django.

Pasang PhytonLink to this heading

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.

Pasang Apache dan mod_wsgiLink to this heading

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 berjalanLink to this heading

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.

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 DjangoLink to this heading

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 pipLink to this heading

Ini adalah cara yang dianjurkan untuk memasang Django.

  1. 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.

  2. 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.

  3. After you've created and activated a virtual environment, enter the command:

    Linux / macOS

    Shell
    $ python -m pip install Django
    

    Windows

    Windows
    ...\> py -m pip install Django
    

Memasang paket penyebaran-tertentuLink to this heading

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 pengembanganLink to this heading

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

  1. Pastikan anda mempunyai Git terpasang dan anda dapat menjalankan perintah nya dari shell. (masukkan git help pada shell prompt untuk mencoba ini.)

  2. Periksa cabang pengembangan Django seperti itu:

    Linux / macOS

    Shell
    $ git clone https://github.com/django/django.git
    

    Windows

    Windows
    ...\> git clone https://github.com/django/django.git
    

    Ini akan membuat sebuah direktori django dalam direktori anda saat ini.

  3. 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.

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

    Linux / macOS

    Shell
    $ python -m pip install -e django/
    

    Windows

    Windows
    ...\> 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.