Connecting URLs, Views & Templates in Django
Connecting URLs, Views & Templates in Django Assuming you have a Job model and want to: Show a list of all jobs on the homepage Show details of a single job on a separate page 1. Create Views in jobs/views.py from django.shortcuts import render, get_object_or_404 from .models import Job # List all jobs def homepage(request): jobs = Job.objects.all() # Fetch all jobs return render(request, 'jobs/home.html', {'jobs': jobs}) # Detail view for a single job def job_detail(request, job_id): job = get_object_or_404(Job, id=job_id) # Get job or 404 if not found return render(request, 'jobs/job_detail.html', {'job': job}) 2. Update portfolio/urls.py Add URL patterns for both views: from django.urls import path from jobs import views urlpatterns = [ path('admin/', admin.site.urls), path('', views.homepage, name='home'), # H...