İçeriğe geç
KURUMSAL Kurumsal teknoloji · İşletmenize özel mühendislik Kurumsal Yazılım · Yönetilen Sunucular · Kurumsal E-posta · LiteSpeed + CloudLinux · Imunify360 Güvenlik · cPanel Yönetim · Uygun pakette 3 Gbps'ye kadar ağ profili
AIOR

PyCharm ile Django Projesi Oluşturma — Sıfırdan Yapılandırma

  • Konu başlatıcısı Konu başlatıcısı Aior
  • Başlangıç tarihi Başlangıç tarihi
  • Öne çıkan

Aior

Administrator

Yetkili üye
Katıldı
2 Nis 2023
Mesajlar
929
Tepki puanı
2
Puan
18
Yaş
41
Konum
Turkey
Web sitesi
aior.com
Konu sahibi

PyCharm Professional ile Django Project Wizard​

PyCharm Professional sürümü Django'ya entegre bir proje oluşturma sihirbazı sunar. Bu sihirbaz virtual environment kurulumundan başlayarak Django paketlerini indirir, ilk proje yapısını oluşturur ve çalışmaya hazır bir geliştirme ortamı sunar. Bu rehber Professional sürümün Django wizard'ını adım adım kullanmayı anlatır.

Yeni Proje Oluşturma​

PyCharm'ı açıp File → New Project menüsünden başlayın. Sol taraftaki proje tipleri listesinde Django'yu seçin. Eğer Django seçeneği yoksa Community sürümü kullanıyorsunuzdur — bu durumda Pure Python seçip elle pip ile Django'yu kurmanız gerekir.

Proje Yapılandırması​

Açılan formda şu alanları doldurun:

Location: /Users/me/Projects/django-app gibi anlamlı bir dizin yolu girin. PyCharm bu yola tüm proje dosyalarını yerleştirir.

Python Interpreter: New environment using Virtualenv seçili olmalı. Base interpreter olarak sisteminizdeki Python 3.10+ sürümünü işaretleyin. Virtual environment proje izolasyonu sağlar; bir projedeki paket sürümleri başka projeyi etkilemez.

Application name: ilk Django app'i için isim verin, örneğin blog veya shop. PyCharm proje yapısını oluştururken bu app'i de hazırlar.

Otomatik Oluşan Yapı​

"Create" butonuna bastıktan sonra PyCharm şu yapıyı oluşturur:

Kod:
django-app/
├── .venv/                 # Virtual environment
├── manage.py              # Django CLI
├── django-app/            # Proje config
│   ├── settings.py
│   ├── urls.py
│   ├── wsgi.py
│   └── asgi.py
├── blog/                  # İlk app
│   ├── migrations/
│   ├── models.py
│   ├── views.py
│   ├── admin.py
│   └── apps.py
└── templates/             # Template dizini
    └── base.html

Settings Dosyasını İnceleme​

settings.py Django'nun en önemli yapılandırma dosyasıdır. PyCharm bunu açar; dikkat edilmesi gereken bölümler:

Kod:
INSTALLED_APPS = [
    # Django built-ins
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Sizin app'leriniz
    'blog',
]

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

Geliştirmede SQLite varsayılan; üretimde PostgreSQL veya MySQL'e geçeceksiniz.

İlk Çalıştırma​

PyCharm'da Run → Run 'django-app' menüsünden veya yeşil "play" butonuyla geliştirme sunucusunu başlatın. Default port 8000'dir; tarayıcıdan http://127.0.0.1:8000/'i ziyaret edin.

Migration uyarısı görüyorsanız:

Kod:
python manage.py migrate

Bu Django'nun built-in tablolarını oluşturur.

Superuser Oluşturma​

Admin paneline erişmek için superuser:

Kod:
python manage.py createsuperuser

Username, e-mail, şifre soracaktır. Sonra http://127.0.0.1:8000/admin/'den girebilirsiniz.

Geliştirme Akışı​

Tipik bir geliştirme döngüsü:

1. Model değiştir — models.py'a yeni alan ekle
2. Migration üret — python manage.py makemigrations
3. Migration uygula — python manage.py migrate
4. View yaz — views.py'ya fonksiyon veya class-based view ekle
5. URL bağla — urls.py'ya path ekle
6. Template oluştur — templates/'a HTML dosya
7. Test et — geliştirme sunucusunda görsel doğrulama

Üretime Geçiş​

Geliştirme tamamlandığında:
- DEBUG = False yapın
- ALLOWED_HOSTS'a domain'inizi ekleyin
- PostgreSQL'e geçin (SQLite üretime uygun değil)
- python manage.py collectstatic çalıştırın
- Nginx + Gunicorn ile servis edin

AIOR hosting paketlerimizde Django projeleri için PostgreSQL + Redis + Nginx + Gunicorn ön-konfigüre olarak gelir; deployment dakikalar içinde tamamlanır.


Django Project Wizard in PyCharm Professional​

PyCharm Professional ships with a built-in Django project wizard. The wizard sets up the virtual environment, installs Django, creates the initial project structure and hands you a ready-to-code dev environment. This guide walks through Professional's Django wizard step by step.

Creating a New Project​

Open PyCharm and choose File → New Project. From the project types on the left, select Django. If you don't see Django, you're on Community — in that case use Pure Python and install Django manually via pip.

Project Configuration​

Fill out the form:

Location: enter a meaningful directory path like /Users/me/Projects/django-app. PyCharm places all project files here.

Python Interpreter: select New environment using Virtualenv. Use a Python 3.10+ base interpreter. The virtual environment isolates this project — package versions here don't leak into other projects.

Application name: name your first Django app, e.g. blog or shop. PyCharm scaffolds this app along with the project structure.

Auto-Generated Structure​

After clicking "Create", PyCharm creates:

Kod:
django-app/
├── .venv/                 # Virtual environment
├── manage.py              # Django CLI
├── django-app/            # Project config
│   ├── settings.py
│   ├── urls.py
│   ├── wsgi.py
│   └── asgi.py
├── blog/                  # First app
│   ├── migrations/
│   ├── models.py
│   ├── views.py
│   ├── admin.py
│   └── apps.py
└── templates/             # Template directory
    └── base.html

Reviewing settings.py​

settings.py is Django's most important config file. PyCharm opens it for you; the key sections:

Kod:
INSTALLED_APPS = [
    # Django built-ins
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Your apps
    'blog',
]

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

SQLite is the default for development; you'll move to PostgreSQL or MySQL in production.

First Run​

In PyCharm, use Run → Run 'django-app' or hit the green "play" button to start the dev server. The default port is 8000 — visit http://127.0.0.1:8000/.

If you see migration warnings:

Kod:
python manage.py migrate

This creates Django's built-in tables.

Creating a Superuser​

For admin access:

Kod:
python manage.py createsuperuser

It prompts for username, email and password. Then sign in at http://127.0.0.1:8000/admin/.

The Development Loop​

A typical cycle:

1. Change model — add a field in models.py
2. Generate migration — python manage.py makemigrations
3. Apply migration — python manage.py migrate
4. Write a view — add a function or CBV in views.py
5. Wire URL — add a path in urls.py
6. Build a template — drop an HTML file under templates/
7. Test — verify visually in the dev server

Moving to Production​

When development is done:
- Set DEBUG = False
- Populate ALLOWED_HOSTS with your domain
- Switch to PostgreSQL (SQLite is not production-ready)
- Run python manage.py collectstatic
- Serve via Nginx + Gunicorn

AIOR hosting packages come with PostgreSQL + Redis + Nginx + Gunicorn pre-configured for Django apps — deployment completes in minutes.
 

Forum istatistikleri

Konular
925
Mesajlar
932
Üyeler
26
En son üye
Jessicawatson

Çevrimiçi üyeler

Şu anda çevrimiçi üye yok.

Öne çıkan içerik

AIOR
AIOR TEKNOLOJİ

Tüm ihtiyaçlarınız için Teklif alın

Hosting · Domain · Sunucu · Tasarım · Yazılım · Mühendislik · Sektörel Çözümler

Teklif al

7/24 Destek · Anında yanıt

Geri
Üst