Skip to content

Commit d49c624

Browse files
committed
2c. Projects App: Views
1 parent 0091ee5 commit d49c624

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

rp-portfolio/personal_portfolio/urls.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
1616
from django.contrib import admin
17-
from django.urls import path
17+
from django.urls import path, include
1818

19-
urlpatterns = [path("admin/", admin.site.urls)]
19+
urlpatterns = [
20+
path("admin/", admin.site.urls),
21+
path("projects/", include("projects.urls")),
22+
]

rp-portfolio/projects/urls.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.urls import path
2+
from . import views
3+
4+
urlpatterns = [
5+
path("", views.project_index, name="project_index"),
6+
path("<int:pk>/", views.project_detail, name="project_detail"),
7+
]

rp-portfolio/projects/views.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
# from django.shortcuts import render
1+
from django.shortcuts import render
2+
from projects.models import Project
23

3-
# Create your views here.
4+
5+
def project_index(request):
6+
projects = Project.objects.all()
7+
context = {"projects": projects}
8+
return render(request, "project_index.html", context)
9+
10+
11+
def project_detail(request, pk):
12+
project = Project.objects.get(pk=pk)
13+
context = {"project": project}
14+
return render(request, "project_detail.html", context)

0 commit comments

Comments
 (0)