diff --git a/django_project/settings.py b/django_project/settings.py index 85d47deb..3d15d45f 100644 --- a/django_project/settings.py +++ b/django_project/settings.py @@ -11,6 +11,7 @@ """ from pathlib import Path +import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -118,8 +119,10 @@ STATIC_URL = 'static/' STATICFILES_DIRS = [ - BASE_DIR / 'static', + BASE_DIR/ 'static' ] + + # Default primary key field type # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field diff --git a/django_project/views.py b/django_project/views.py index f9042b4c..cd7fc4d5 100644 --- a/django_project/views.py +++ b/django_project/views.py @@ -1,17 +1,27 @@ import requests from django.shortcuts import render +import random -def home(request): - # USING APIS => Example 1 - response = requests.get('https://api.github.com/events') - data = response.json() - result = data[0]["repo"] +def index(request): + # Fetch a random fact + fact_response = requests.get('https://uselessfacts.jsph.pl/random.json? language=en') + fact_data = fact_response.json() + fact = fact_data['text'] - # Example 2 - reponse2 = requests.get('https://dog.ceo/api/breeds/image/random') - data2 = reponse2.json() - result2 = data2["message"] + # Fetch student data + student_response = requests.get('https://freetestapi.com/api/v1/students') + student_data = student_response.json() + students = student_data['students'] + # Shuffle the list of students + random.shuffle(students) - - return render(request, 'templates/index.html', {'result': result, 'result2': result2}) \ No newline at end of file + # Get the name of the first student + if students: + first_student_name = students[0]['name'] + else: + first_student_name = "No students available" + + # Render the index.html template with data + return render(request, 'index.html', {'fact': fact, 'name': + first_student_name}) diff --git a/static/styles.css b/static/styles.css index 530d510b..1850312a 100644 --- a/static/styles.css +++ b/static/styles.css @@ -1,9 +1,19 @@ body{ - background: hotpink + padding:0; + margin:0; + font-style:bold; + background-color:mistyrose; + } - -img{ - width: 100px; - height: 100px; - border-radius: 9999; +h1{ + color:black; + font-weight:bolder; + align-items:center; + text-align:center; } + +p{ + font-weight:bolder; + align-items:center; + text-align:center; +} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index b0f60817..4087215e 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,22 +1,21 @@ -{% load static%} +{% load static %} - - - Document + + Blog Website -

Hello, My name is Evans

- - {{result}} - -

Random Pet

-{{result2}} - random pet - +

Hello developer

+

I'm here to generate for you random dev quotes from philosophers ssup yoh


+

Random Fact

+ {{fact}} +

Random Student

+ {{name}} +
+

All rights reserved ©, Daniel Mukenya Nyongesa ™

\ No newline at end of file