Django Career App Django.How

Author avatar wrote on 26/05/2022

  • Create App
  • Configuration Admin Area
  • Allowing Managing Careers Using Admin Panel
  • Build Front Facing Page
  • Create View
  • Creating URLs
  • Create HTML Template for this App

Create App

  1. type python manage.py startapp career career is an example of app name

  2. go to the file career/models.py and declare your class

3.Go to your app folder and open settings.py then declare your app under INSTALLED_APPS


# Application definition

INSTALLED_APPS = [
    ...
    'career.apps.CareerConfig',
    ...
]

4.Create the migration, make sure in the terminal you are in the right folder and pipenv shell is running then type python manage.py makemigrations career this will create the necessary python files

5.Make the complete migration to create the tables in the datbase by typing python manage.py migrate

Configuration Admin Area

Allowing Managing Careers Using Admin Panel

Open career/admin.py file and import the new models and register them under admin:

Notice: must be installedSummernote app. Detaile info how to install it you can find here https://djangocentral.com/integrating-summernote-in-django/

Build Front Facing Page

Create View

We will have just one page with list of careers and contact form, so inside career/views.py we need to define just one function.

1.Bring the model from .models import Career, Job_requests

2.Define function and get all careers


def index(request):
    careers = Career.objects.all()

3.Check if form was submited and if yes save new job request to database

4.Return data to template file


context = {
        'careers': careers
    }
return render(request, 'career/index.html', context)

Creating URLs

1.Create file urls.py in app folder

2.Add URL rules to this file


from django.urls import path

from . import views

urlpatterns = [
    path('', views.index, name='career')
]

3.In the main app folder, oper urls.py file and include the file you created


urlpatterns = [
    ...
    path('career/', include('career.urls')),
    ...
]

Create HTML Template for this App

1.Create career folder inside templates

2.Create index.html file inside templates/career folder

3.Copy html code to this file from here:

CRUDgen Django CRUD generator