From f6da6d8c232d8abf6c9017305d56f3310b96e1db Mon Sep 17 00:00:00 2001 From: FeliPython Date: Thu, 18 Apr 2024 22:33:45 -0300 Subject: [PATCH] Extend documentation on URL mapping and views Expanded the section on URL mapping and views to include a detailed walkthrough of creating an endpoint up to Django server running. Provided specific codes for 'music' app url patterns, setting up 'urls.py' in music folder, and implementing function view 'index'. Also introduced the upcoming section on Django Rest Framework usage. --- docs/images/my_first_api.png | Bin 0 -> 7124 bytes docs/index.md | 45 ++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 docs/images/my_first_api.png diff --git a/docs/images/my_first_api.png b/docs/images/my_first_api.png new file mode 100644 index 0000000000000000000000000000000000000000..1b211bd39bdef090b7797b7300c22bd0b077fe26 GIT binary patch literal 7124 zcmeI1_d8o}{P1;r&{nC@qGo9+En*Wy`w=^$LW|ZYYE!kTRhuGq5$l5(v6YUPtxaOY zC?!gaq^Q_?eNUh3dVYNVg6I3g$(3`ilXJiC`+mRgbH84ReFE3Ke)aZM8XB7G+FDQq z4b25#;5(6?7Wj;FA=%T=aAj*l9~=2utmV=rad&ZQEJ+D*#=D1JgAGoa2-w3?po1LY zcOQORzN$OruPsu(5gTZ|i* z=B_O-XXPFqt+xdj2iW9VOH>m==jQzZb9G5dVVbBWDnR0vJWWW}6H6ydar=Cn1n<%AD*MsiT1DDXl&*7d_j5|4!!aW@At)R%$O#3Cq zwS|-5 z8?a0@Udg^Q(DG8!f9he+peSeIc3?g-f?%^XuwtaM%MG-1RZyrH!ES3a_%IS?;BVgv z@wy!+-ss>uql3u=SqOH_a4KA}B;SY^^zu>1qr;|t(TYyjLx}m)`ZAt+{lnezug_qO)oo`-R{Jx) zOqx92MheU5)b`-xHFmifuTein?}-%G#kuY5@&~Apv%`*y*B%bP4rqOA|F7}p!>@B; zb?`Itx-4tY`X5Lx^RADPJVl*rrCRM1e&Un6^`Lor(T7YWrbF;*CF^HkD5hd+n<7oC zzWjP?wLKv3);x%VIl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g-I9A2XN(7Z??-5OoGPLV9JT=mIW_qK-|`coJ!g`poog`;%wXNY->0o1b&v>G-&DFDD(Z@UPBD9+fAvjMv9+b+YQaxZv&x zhX7Kg3;Y=h)ywVW-imCsy%k zKtZi-w5$h7lpr&SRT_gi9lQa5n1$6GExjFu2uF|Uc-RswbMXu-w05d_uyb^{Sd_cpKD2KaI7ng zuc&kK2Ekia7%m!pFN))}G{_Fjyl1a1sG-jWNAhml{ksMDKF0>z*`R&b6Yh%-e6;$8 zY4`Lnd|-wV!9~(f)l)W_8$tC`)rrDuA15pVy7m=rS;7RKruEnV*#f+kOBx;c zc7JVPs#L=d;q+C(hKWcWzlyrl$K{_n4Wp8XCrkeX*?StQUZ7 z>bxWiJ99F%w3rM>qTG^FD%Pv{&RCd}_kf#1`#S6_O@I?>!4mMs6-eb9Fo&Wa$@nrS xUnCIKp;w`v?93uJ{`cbl4#@u($#AH;ws-JzX(>qo__vNmTOAIq{`Y0r{{Yo*@*4mE literal 0 HcmV?d00001 diff --git a/docs/index.md b/docs/index.md index 3554f9b..6704851 100644 --- a/docs/index.md +++ b/docs/index.md @@ -155,9 +155,48 @@ class Song(models.Model): ## URL Mapping and Views -- 🎬 Lecture : Explanation of URL configurations and Views/ViewSets in Django. -- 💻 Exercise : Students implement URL mapping and views for a sample API. -- 💡 Purpose: Practical understanding of Django's routing and controller mechanisms. +Now let's go to the URL Mapping, we need to associate the url with the handler functions that are called as view in Django. To create a simple endpoint that works. + + +```python +# first_api.urls.py +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path("admin/", admin.site.urls), + path("", include('music.urls')), +] +``` + +You need to create a file `urls.py` inside music folder and make it look like the example below. + +```python +# music.urls.py +from django.urls import path + +from . import views + +urlpatterns = [ + path('', views.index, name='index') +] +``` + +And last but not least you need to create this +you need to create the view. A function view in this case. + +```python +from django.http import HttpResponse + + +def index(_request): + return HttpResponse("My first API!") +``` + +So no you can use the command `task r` to start our django server, so you can access http://127.0.0.1:8000/ to see it. +![my_first_api.png](images/my_first_api.png) + +Until here we just looked at Django stuff. Now we will dive into Django Rest Framework(DRF) stuff. ## Serializers