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
1 change: 1 addition & 0 deletions django_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@

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
22 changes: 13 additions & 9 deletions django_project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@

def home(request):
# USING APIS => Example 1
response = requests.get('https://api.github.com/events')
data = response.json()
result = data[0]["repo"]
# views.py
import requests
from django.shortcuts import render

# Example 2
reponse2 = requests.get('https://dog.ceo/api/breeds/image/random')
data2 = reponse2.json()
result2 = data2["message"]
def home(request):
# Fetching data from the Car API
car_response = requests.get('https://api.Bentley.com/cars')
car_data = car_response.json()
car_result = car_data["cars"]

# Fetching data from the Ship API
ship_response = requests.get('https://api.maersk.com/ships')
ship_data = ship_response.json()
ship_result = ship_data["ships"]


return render(request, 'templates/index.html', {'result': result, 'result2': result2})
return render(request, 'index.html', {'car_result': car_result, 'ship_result': ship_result})
47 changes: 41 additions & 6 deletions static/styles.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
body{
background: hotpink
/* styles.css */

body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}

.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}

h1 {
color: #333;
}

ul {
list-style-type: none;
padding: 0;
}

li {
margin-bottom: 10px;
}

/* Styling for Car Data */
.car-section {
margin-bottom: 30px;
}

.car-section h1 {
color: #007bff; /* Blue color */
}

/* Styling for Ship Data */
.ship-section {
margin-top: 30px;
}

img{
width: 100px;
height: 100px;
border-radius: 9999;
.ship-section h1 {
color: #28a745; /* Green color */
}
33 changes: 18 additions & 15 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
{% 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>
<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" type="text/css" href="{% static 'styles.css' %}">
<title>Welcome to see land and water transport machines</title>
</head>
<body>
<h1>Hello, My name is Evans </h1>
<h1>Car Data</h1>
<ul>
{% for car in car_result %}
<li>{{ car }}</li>
{% endfor %}
</ul>

{{result}}

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

<h1>Ship Data</h1>
<ul>
{% for ship in ship_result %}
<li>{{ ship }}</li>
{% endfor %}
</ul>
</body>
</html>
</html>