In-Class Activity 11: Styling with Django and Bootstrap:

Objective: Continue styling the Django web application. Use Plotly to create a donut chart that displays each topic as a percentage of total entries.

Description: Continue using Bootstrap and the Bootswatch themes to style the new_topic.html, topics.html and topic.html pages. Add the donut chart to the bar_chart.html page and place both charts in a table row.

  • Make a copy of your Activity10 folder and name the folder Activity11-StyleWithDjango. After the activity is completed, take four screenshots matching the solution images below and submit it to the first quiz question on Canvas.
  • Navigate to the directory that contains manage.py and open the folder in VS code.

Part 1:

  1. Modify the new_topic.html file by loading bootstrap5 and use the {% bootstrap_form %} template tag instead of the {{ form.as_p }}.
  2. Modify the topics.html file by adding the heading Topics inside the page_header block. Simply style each topic as an < h3> element and do the same for the link to add a new topic.
  3. Modify the topic.html page by using Bootstrap cards to make each entry stand out.

Part 2:

  1. Modify the bar_chart() function in the views.py file and create a pie chart using Plotly express that displays each topic as a percentage of total entries. Use the dataframe, names, values, and title properties. Set the hole value to occupy 50% of the area. Name the donut chart, Topics as a Percentage of Total Entries.
  2. Modify the bar_chart.html file. Place the bar and donut Plotly charts inside a Bootswatch-themed table row.
    • Note: Source code examples of Bootstrap tables can be referenced on the Bootswatch site: https://bootswatch.com

new_topic.html A styled Add a New Topic form rendered in a Django web app using Bootstrap. The page displays a navigation bar with the brand name CODE JOURNALS and links for Topics and Other Menu Items. Below the navbar is a heading that reads Add a New Topic followed by a Bootstrap-styled text input field and a red rounded Add Topic button. The layout is clean and minimal with a white background, reflecting a functional and straightforward academic project interface.


topics.html A Bootstrap-styled Topics page in a Django web app. The page shows a navigation bar with the brand CODE JOURNALS and links for Topics and Other Menu Items. Below the navbar is a bold heading that reads Topics followed by a list of topic names displayed as h3-sized links, each representing a subject like Python or JavaScript. At the bottom of the list is an Add a new topic link styled as an h3 element. The page has a white background and a clear, organized academic tone.


topic.html A Bootstrap-styled individual topic detail page in a Django web app. The navigation bar displays CODE JOURNALS with Topics and Other Menu Items links. The main content area shows a topic heading followed by journal entries presented as Bootstrap cards, each card containing the date, title, and body text of an entry. An Add new entry link appears below the cards. The white background and card-based layout give the page a structured and readable academic appearance.


bar_chart.html A Bootstrap-styled charts page in a Django web app displaying two Plotly visualizations side by side inside a Bootswatch-themed table row. The left chart is a vertical bar chart titled Number of Entries per Topic showing the count of journal entries for each topic. The right chart is a donut chart titled Topics as a Percentage of Total Entries showing each topic as a colored segment with percentage labels. The navigation bar at the top reads CODE JOURNALS with Topics and Other Menu Items links. The page has a light background and a data-focused, analytical tone.