Django Academy · Ders

STATICFILES ve static Etiketi

Varlıklarınızı düzenleyin ve bunlara başvurun.

1. ders / 413 adım

STATICFILES ve static Etiketi, CoddyKit'te ücretsiz bir Django Academy dersidir. Bu, 4 dersinin 1. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Django Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Django Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

What Static Files Are

Your CSS, JavaScript, and design images do not change per request. Django calls these static files and serves them separately from your Python views. 🎨

The static App

Django ships django.contrib.staticfiles in INSTALLED_APPS by default. It finds, collects, and serves your assets so you do not wire that up by hand.

INSTALLED_APPS = [
    'django.contrib.staticfiles',
]

Where Files Live

By convention you keep an app's assets inside a folder named static right next to its views and templates. Django scans every app for that folder.

blog/
  static/
    blog/
      style.css

Namespace Your Folder

Nest assets under a folder matching the app name, like static/blog/. This namespacing stops two apps from clobbering each other's style.css.

The STATIC_URL Setting

The STATIC_URL setting is the public path prefix browsers use to fetch assets. Requests starting with this prefix are routed to your static files.

STATIC_URL = '/static/'

Load the static Tag

To reference assets in a template, first load the tag library with load static at the very top of the file.

{% load static %}

Use the static Tag

The static tag turns a relative asset path into the correct full URL, so you never hardcode STATIC_URL into your HTML.

<link rel="stylesheet" href="{% static 'blog/style.css' %}">

Why Not Hardcode

If you wrote /static/blog/style.css by hand, changing STATIC_URL later would break every page. The static tag keeps your links flexible. ✅

Linking JavaScript

The same static tag works for any asset type. Point a script tag at a JS file and Django resolves the path for you.

<script src="{% static 'blog/app.js' %}"></script>

STATICFILES_DIRS

For project-wide assets that belong to no single app, add their folders to STATICFILES_DIRS and Django will search there too.

STATICFILES_DIRS = [BASE_DIR / 'assets']

Finders Do the Work

Behind the scenes, static finders walk every app's static folder plus STATICFILES_DIRS to locate the file a template asks for.

Quick Check

Let us check how you reference a static file in a template.

Recap

You learned that static files are your CSS and JS, that they live in namespaced static folders, and that the static tag builds their URLs cleanly. 🎉

Başlamak ücretsiz

Yapay zeka eğitmeniyle Python öğren — ücretsiz

Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.

Kurslar
30
Dersler
120

Sıkça Sorulan Sorular

“STATICFILES ve static Etiketi” dersi ücretsiz mi?

Evet — “STATICFILES ve static Etiketi” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Django Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Django Academy kursu toplamda 4 dersten oluşur.

“STATICFILES ve static Etiketi” dersinde ne öğreneceğim?

Varlıklarınızı düzenleyin ve bunlara başvurun. Django Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Django Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Django Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 1. dersidir.

“STATICFILES ve static Etiketi” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Django Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Django Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. STATICFILES ve static Etiketi
  2. Üretim için collectstatic
  3. MEDIA_ROOT ve Dosya Yüklemeleri
  4. ImageField ve Yüklemeleri Sunma
← Django Academy Sayfasına Dön