Band Listing


Download 24.81 Kb.
bet10/10
Sana08.06.2023
Hajmi24.81 Kb.
#1463530
1   2   3   4   5   6   7   8   9   10
Bog'liq
Python методичка

class Member(models.Model):
"""A model of a rock band member."""
name = models.CharField("Member's name", max_length=200)
instrument = models.CharField(choices=(
('g', "Guitar"),
('b', "Bass"),
('d', "Drums"),
),
max_length=1
)
band = models.ForeignKey("Band")


4-DARS
Url orqali pagelar ochish (“Hello World”)
URL sxemasi yuqori sifatli veb-ilovaning muhim detalidir. Django URL-ning chiroyli dizaynini rag'batlantiradi va .php yoki .asp kabi URL-larga hech qanday noqulaylik tug'dirmaydi.


Ilova uchun URL manzillarini loyihalash uchun siz URLconf deb nomlangan Python modulini yaratasiz. Ilovangiz uchun mundarijaga o'xshab, u URL namunalari va sizning ko'rinishlaringiz o'rtasidagi oddiy xaritani o'z ichiga oladi.
from django.urls import path


from . import views


urlpatterns = [
path('bands/', views.band_listing, name='band-list'),
path('bands//', views.band_detail, name='band-detail'),
path('bands/search/', views.band_search, name='band-search'),
]
from django.shortcuts import render


def band_listing(request):
"""A view of all bands."""
bands = models.Band.objects.all()
return render(request, 'bands/band_listing.html', {'bands': bands})


5-DARS
Djangoda Template yaratish, base.html, dasturga test yozishni organish
Django shablon tili kuch va qulaylik o'rtasidagi muvozanatni saqlash uchun mo'ljallangan. U HTML bilan ishlashga odatlanganlar, masalan, dizaynerlar va ishlab chiquvchilar uchun o'zlarini qulay va oson o'rganish uchun mo'ljallangan. Ammo u moslashuvchan va juda kengayishi mumkin, bu esa ishlab chiquvchilarga kerak bo'lganda shablon tilini kengaytirishga imkon beradi.


Band Listing


All Bands



    {% for band in bands %}

  • {{ band.get_absolute_url }}">{{ band.name }}


    {% if band.can_rock %}
    This band can rock!
    {% endif %}

  • {% endfor %}


Download 24.81 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling