You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardexpand all lines: docs/index.md
+42-3
Original file line number
Diff line number
Diff line change
@@ -155,9 +155,48 @@ class Song(models.Model):
155
155
156
156
## URL Mapping and Views
157
157
158
-
- 🎬 Lecture : Explanation of URL configurations and Views/ViewSets in Django.
159
-
- 💻 Exercise : Students implement URL mapping and views for a sample API.
160
-
- 💡 Purpose: Practical understanding of Django's routing and controller mechanisms.
158
+
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.
159
+
160
+
161
+
```python
162
+
# first_api.urls.py
163
+
from django.contrib import admin
164
+
from django.urls import path, include
165
+
166
+
urlpatterns = [
167
+
path("admin/", admin.site.urls),
168
+
path("", include('music.urls')),
169
+
]
170
+
```
171
+
172
+
You need to create a file `urls.py` inside music folder and make it look like the example below.
173
+
174
+
```python
175
+
# music.urls.py
176
+
from django.urls import path
177
+
178
+
from . import views
179
+
180
+
urlpatterns = [
181
+
path('', views.index, name='index')
182
+
]
183
+
```
184
+
185
+
And last but not least you need to create this
186
+
you need to create the view. A function view in this case.
187
+
188
+
```python
189
+
from django.http import HttpResponse
190
+
191
+
192
+
defindex(_request):
193
+
return HttpResponse("My first API!")
194
+
```
195
+
196
+
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.
197
+

198
+
199
+
Until here we just looked at Django stuff. Now we will dive into Django Rest Framework(DRF) stuff.
0 commit comments