Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DjangoGirls Seoul | Django Study #2 Django MTV

Beomi
February 12, 2017

DjangoGirls Seoul | Django Study #2 Django MTV

DjangoGirls Seoul 장고 입문 스터디 #2 Django MTV

Beomi

February 12, 2017
Tweet

More Decks by Beomi

Other Decks in Technology

Transcript

  1. Model (ݽ؛) • Database৬ Djangoܳ োѾ • DB੄ Column੄ ഋधਸ

    ੿੄ • ؘ੉ఠ੄ ҙ҅ܳ ੿੄ from django.db import models class SomeInfo(models.Model): name = models.CharField(max_length=200) • name੉ۄח ੉ܴ੄ Column੉ ࢤࢿغҊ ୭؀ӡ੉о 200ਵ۽ ઁೠ Ѧܽ ೙٘۽ ੿੄ػ׮.
  2. Model Field (ݽ؛೙٘) • models੄ SomeInfo ௿ېझ => DB੄ SomeInfo

    Table • SomeInfo ௿ېझ੄ name => DB੄ name Column Model Manager (ݽ؛ ݒפ੷) • DB੄ Queryܳ ୊ܻ • SomeInfo.objects.ޤޤ ࣘࢿਵ۽ ઁҕ
  3. User Method (ࢎਊ੗ ݫࣗ٘) • ݽ؛ ݫࣗ٘о ݽ؛ী ੿੄ •

    SomeInfo١੄ ݽ؛ classউী ੿੄ػ ೣࣻ
  4. Rela%onship (ҙ҅) • ݽ؛੄ class݃׮ (DB੄ table݃׮)੄ ҙ҅ • OneToOneField(1:1)

    / ForeignKey(1:n) / ManyToManyField(n:n) class UserInfo(models.Model): user = models.OneToOneField(settings.AUTH_USER_MODEL) # ਬ੷о о૓ ਬ੷ ੿ࠁח ױ ೞա! nickname = models.CharField(max_length=20) class Post(models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL) # ਬ੷о ৈ۞ѐ੄ Ӗਸ ॶ ࣻ ੓׮. title = models.CharField(max_length=200) content = models.TextField() class Tag(models.Model): post = models.ManyToManyField(Post) # ೠ Postী ৈ۞ѐ੄ కӒо ׳ܾ ࣻ ੓Ҋ, ೠ కӒী ৈ۞ѐ੄ Postо ੓׮.
  5. Rela%onship (ҙ҅) • OneToOneField u = User(user=request.user) u.userinfo.nickname # user੄

    UserInfo੄ nickname • ForeignKey u.post_set.all() # userо ॵ ݽٚ post • ManyToManyField p = Post.objects.first() p.tag_set.all()
  6. Template (మ೒݁) • Python ё୓ܳ HTMLীࢲ ੉ਊೡ ࣻ ੓ب۾ •

    Django Template ޙߨਸ ੉ਊ (഑਷ Jinja2) • Viewীࢲ ֈѹ઱ח ؘ੉ఠܳ ੉ਊ • renderೣࣻীࢲ ੉ਊؽ • MVCݽ؛੄ V(࠭)ী ೧׼ؽ
  7. Template (మ೒݁) <!-- ߸ࣻ some_var --> {{ some_var }} <!--

    కӒ some_tag --> {% some_tag %} <!-- ೙ఠ --> {{ some_var | filter }} <!-- ઱ࢳ --> {# ઱ࢳ #} {% comment %} {% endcomment %}
  8. View (࠭) • Djangoо URL੽Ӕী ٮۄ ߈਽ਸ ࠁ੉ח Ҕ •

    MVCݽ؛੄ C(ஶ౟܀۞) ৉ೡ • Func4on Based View vs Class Based View • request -> response
  9. HTTP Request • method / / GET, POST, .. •

    GET, POST -> DICT(k:v) • FILES • user • session • ...
  10. REST and CRUD • HTTP Methodח POST / GET /

    PUT / DELETE • CRUDח Create / Read / Update / Delete • пп ؀਽
  11. RESTful੄ ੢੼ • OpenAPI ઁҕ੉ ए਑ • ਗೞח ؘ੉ఠ ఋੑਵ۽

    ઁҕ (JSON / XML / RSS) • StateLessࢲߡ (ਃ୒р Contextח ੷੢غ૑ ঋ਺) • ۽٘ߖ۠यী ਬܻ • ࣁ࣌ ࢎਊਸ ӂ੢ೞ૑ ঋ਺ (п ਃ୒ী ة݀੸ਵ۽ ߈਽) • ۽Ӓੋ ١਷ Tokenਸ ੉ਊ೧ ੋध