Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion django_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
32 changes: 21 additions & 11 deletions django_project/views.py
Original file line number Diff line number Diff line change
@@ -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})
# 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})
22 changes: 16 additions & 6 deletions static/styles.css
Original file line number Diff line number Diff line change
@@ -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;
}
23 changes: 11 additions & 12 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
{% load static%}
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{% static 'styles.css' %}" />
<!-- <link rel="stylesheet" href="/static/styles.css" /> -->
<title>Document</title>
<link rel="stylesheet" href="{% static 'styles.css' %}">
<title>Blog Website </title>
</head>
<body>
<h1>Hello, My name is Evans </h1>

{{result}}

<h1>Random Pet</h1>
{{result2}}
<img src={{result2}} alt="random pet" />

<h1>Hello developer </h1>
<p>I'm here to generate for you random dev quotes from philosophers ssup yoh</p><br>
<p>Random Fact</p>
{{fact}}
<p>Random Student</p>
{{name}}
<br>
<p>All rights reserved &copy;, Daniel Mukenya Nyongesa &trade;</p>
</body>
</html>