url Etiketi ve static Etiketi
Yolları sabit kodlamadan rotaları ve varlıkları bağlayın.
url Etiketi ve static Etiketi, CoddyKit'te ücretsiz bir Django Academy dersidir. Bu, 4 dersinin 4. 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.
Never Hardcode Paths
Typing URLs and file paths by hand breaks the moment they change. Django gives you the url and static tags to build them safely. 🔗
The url Tag Builds Routes
The url tag turns a route name into its real path. Rename the URL pattern later and every link updates automatically.
<a href="{% url 'home' %}">Home</a>Name Your Routes First
For url to work, give each pattern a name in urls.py. That name is the stable handle the template refers to.
path("about/", views.about, name="about")Passing URL Arguments
If a route needs a value, pass it after the name. Django slots the argument into the path where the converter expects it.
{% url 'post_detail' post.id %}Namespaced URL Names
When an app sets an app_name, reference routes with a prefix like blog:detail to avoid clashing with other apps.
{% url 'blog:detail' post.id %}The static Tag for Assets
The static tag builds the correct URL to a CSS, JS, or image file, even when storage paths differ in production.
{% static 'css/style.css' %}Load static First
Before using the tag you must load static near the top of the template, which pulls the tag into that file.
{% load static %}Linking a Stylesheet
Combine the pieces to link a stylesheet the safe way, so the path stays valid no matter where files are served from.
<link rel="stylesheet" href="{% static 'css/style.css' %}">Showing an Image
The same static tag works for images. Point it at a file under your static folder and Django resolves the full URL.
<img src="{% static 'img/logo.png' %}">Why static Matters
In production, assets often move to a CDN or hashed path. The static tag hides that, so your templates never need editing.
Two Tags, One Goal
Both tags share a purpose: let Django compute paths so you do not. Use url for views and static for files.
Quick Check
Pick the right tag for the right job.
Recap: Safe Links
You learned to build view paths with the url tag and asset paths with static, after loading static. That wraps up rendering HTML with data.
Sıkça Sorulan Sorular
“url Etiketi ve static Etiketi” dersi ücretsiz mi?
Evet — “url Etiketi 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.
“url Etiketi ve static Etiketi” dersinde ne öğreneceğim?
Yolları sabit kodlamadan rotaları ve varlıkları bağlayın. 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 4. dersidir.
“url Etiketi 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
- render() ve Şablon Bağlamı
- Şablon Etiketleri ve Filtreleri
- extends ve block ile Şablon Kalıtımı
- url Etiketi ve static Etiketi