Django Job Board in Python
About the project: This is DJango project for creating Job Board in Python. Django is a good choice for building robust web applications like a job board.
Since a Django project consists of many interlinked files (models, views, templates, settings), we shall provide the essential code snippets for the core files you'll need.
Crucial Setup Steps:
- Install Django:
pip install django
django-admin startproject job_board_project
cd job_board_project
and then python manage.py startapp jobs
You will need to place these files in the corresponding locations:
- The settings.py content replaces the existing file in job_board_project/settings.py.
- The models.py, views.py, and urls.py go inside the new jobs directory:
job_board_project/jobs/. - The HTML file goes inside a new templates subdirectory:
job_board_project/jobs/templates/jobs/job_list.html. - You will also need a main urls.py in the project root (job_board_project/urls.py) to link the app's URLs. We shall include this as well.
1. Project Configuration
This file sets up the project, adds the new jobs app, and configures templates.
"""
Django settings for job_board_project project.
This is a minimal settings file adapted for the example.
"""
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-example-key-to-be-changed!'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
# Standard Django apps (mostly omitted for brevity, but needed in real project)
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# 1. Register the new 'jobs' app
'jobs',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'job_board_project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# DIRS is often empty because we use app-specific templates directories
'DIRS': [],
'APP_DIRS': True, # This tells Django to look in the 'templates' folder inside each app
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'job_board_project.wsgi.application'
# Database - using default SQLite for simplicity
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Time zone configuration
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = 'static/'
# Default primary key field type
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
2. Job App Models
This file defines the database structure for a single job posting.
from django.db import models
from datetime import date
class JobPosting(models.Model):
"""
Defines the structure for a single job posting on the board.
"""
JOB_TYPE_CHOICES = [
('FT', 'Full-Time'),
('PT', 'Part-Time'),
('CT', 'Contract'),
('IN', 'Internship'),
]
title = models.CharField(max_length=200, help_text="Title of the job, e.g., 'Senior Python Developer'")
company = models.CharField(max_length=100)
location = models.CharField(max_length=100, default="Remote")
description = models.TextField()
salary = models.IntegerField(blank=True, null=True, help_text="Annual salary in USD")
job_type = models.CharField(
max_length=2,
choices=JOB_TYPE_CHOICES,
default='FT',
)
date_posted = models.DateField(default=date.today)
def __str__(self):
"""Returns the job title and company for easier admin readability."""
return f"{self.title} at {self.company}"
class Meta:
# Order jobs by the date they were posted, newest first
ordering = ['-date_posted']
3. Job App Views
This file contains the application logic, which queries the database and renders the template.
from django.shortcuts import render
from .models import JobPosting
def job_list(request):
"""
Fetches all job postings from the database and passes them to the template.
"""
# Use .all() and Django's default ordering (defined in models.py)
jobs = JobPosting.objects.all()
# Context dictionary holds data to be passed to the template
context = {
'jobs': jobs,
'job_count': jobs.count()
}
# Render the HTML template, passing the context data
return render(request, 'jobs/job_list.html', context)
4. Job App URLs
This file maps specific paths within the jobs app to the view functions.
from django.urls import path
from . import views
# Set an app name to avoid name clashes if you have multiple apps
app_name = 'jobs'
urlpatterns = [
# Path for the homepage of the job board (e.g., /jobs/)
path('', views.job_list, name='list'),
# You could add other paths here later, like:
# path('<int:job_id>/', views.job_detail, name='detail'),
]
5. Project Root URLs
This file links the main project URL structure to include the URLs from the jobs app.
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
# Include all URLs defined in jobs/urls.py under the path 'jobs/'
# This makes the main job list available at http://127.0.0.1:8000/jobs/
path('jobs/', include('jobs.urls')),
]
6. Template (HTML)
This is the front-end that displays the list of jobs. It uses basic inline styling for a clean look.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Django Job Board</title>
<style>
body { font-family: 'Arial', sans-serif; background-color: #f4f7f6; margin: 0; padding: 0; }
.container { max-width: 900px; margin: 40px auto; padding: 20px; }
h1 { color: #2c3e50; text-align: center; margin-bottom: 20px; }
.job-card {
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 25px;
margin-bottom: 20px;
border-left: 5px solid #3498db;
transition: transform 0.2s;
}
.job-card:hover {
transform: translateY(-3px);
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.15);
}
.job-title { font-size: 1.5em; color: #3498db; margin-top: 0; }
.job-company { font-weight: 600; color: #7f8c8d; }
.job-details { margin-top: 15px; font-size: 0.9em; display: flex; flex-wrap: wrap; gap: 10px 30px; }
.detail-item span { font-weight: bold; color: #2c3e50; }
.description { margin-top: 15px; border-top: 1px dashed #ecf0f1; padding-top: 15px; color: #555; }
.badge { display: inline-block; background-color: #2ecc71; color: white; padding: 4px 8px; border-radius: 4px; font-size: 0.8em; font-weight: 600; }
.empty-state { text-align: center; color: #95a5a6; padding: 50px; border: 2px dashed #bdc3c7; border-radius: 8px; }
</style>
</head>
<body>
<div class="container">
<h1>Current Job Openings ({{ job_count }} Available)</h1>
{% if jobs %}
{% for job in jobs %}
<div class="job-card">
<h2 class="job-title">{{ job.title }}</h2>
<p class="job-company">{{ job.company }} · {{ job.location }}</p>
<div class="job-details">
<div class="detail-item"><span>Type:</span> <span class="badge">{{ job.get_job_type_display }}</span></div>
{% if job.salary %}
<div class="detail-item"><span>Salary:</span> ${{ job.salary|floatformat:0 }}</div>
{% endif %}
<div class="detail-item"><span>Posted:</span> {{ job.date_posted }}</div>
</div>
<div class="description">
<p>{{ job.description|truncatechars:200 }}</p>
<!-- In a full app, this would link to a job detail page -->
<a href="#" style="color: #3498db; text-decoration: none; font-weight: 600;">View Details →</a>
</div>
</div>
{% endfor %}
{% else %}
<div class="empty-state">
<p>No job postings found yet. Time to add some!</p>
</div>
{% endif %}
</div>
</body>
</html>
Next Steps to Run the Project
To make this functional, you need to execute these commands in your project's root directory (job_board_project/):
- Run Migrations: This creates the JobPosting table in your database.
- Create Superuser (Optional but Recommended): This lets you log into the admin panel to add job postings.
- Run the Server:
- View the App: Once the server is running, navigate your browser to: http://127.0.0.1:8000/jobs/
python manage.py makemigrations jobs
python manage.py migrate
python manage.py createsuperuser
*You'll need to register your model in `jobs/admin.py` to manage it, but that file is omitted for brevity.*
python manage.py runserver
← Back to Projects
