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
11 changes: 5 additions & 6 deletions django_project/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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 All @@ -25,7 +25,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = [".replit.dev", ".replit.app"]
ALLOWED_HOSTS = []
CSRF_TRUSTED_ORIGINS = ["https://*.replit.dev", "https://*.replit.app"]

# Application definition
Expand Down Expand Up @@ -115,11 +115,10 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/5.0/howto/static-files/

STATIC_URL = 'static/'
STATIC_URL='static/'

STATICFILES_DIRS = [BASE_DIR / 'static']

STATICFILES_DIRS = [
BASE_DIR / 'static',
]
# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

Expand Down
10 changes: 6 additions & 4 deletions django_project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from . import views

from django.contrib import admin

from . import views
from django.urls import path

urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name='home'),
path('', views.index, name='index'),


]
23 changes: 12 additions & 11 deletions django_project/views.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import requests
from django.shortcuts import render
from django.shortcuts import render

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):
response = requests.get('https://uselessfacts.jsph.pl/random.json?language=en')
data = response.json()
fact = data['text']

# Example 2
reponse2 = requests.get('https://dog.ceo/api/breeds/image/random')
data2 = reponse2.json()
result2 = data2["message"]
r3 = requests.get('https://dog.ceo/api/breeds/image/random')
res3 = r3.json()
dog = res3['message']

response2 = requests.get('https://freetestapi.com/api/v1/students')
data2 = response2.json()
name = data2[0]['name']

return render(request, 'templates/index.html', {'fact': fact, 'dog': dog, 'name': name})

return render(request, 'templates/index.html', {'result': result, 'result2': result2})
4 changes: 4 additions & 0 deletions static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ body{
background: hotpink
}

h1{
align-items: center;
}

img{
width: 100px;
height: 100px;
Expand Down
30 changes: 21 additions & 9 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
{% load static%}
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome to Random Content</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" href="{% static 'styles.css' %}" />
<!-- <link rel="stylesheet" href="/static/styles.css" /> -->
<title>Document</title>

</head>
<body>
<h1>Hello, My name is Evans </h1>

{{result}}
<h1>Random Fact</h1>
<div class="random-fact-card">
{{fact}}
</div>

<h1>Random Student</h1>
<div class="random-student-card">
{{name}}
</div>

<h1>Random Image</h1>
<div class="random-image-card">
{{dog}}
<img src="{{dog}}" alt="Random dog">
</div>

<button onclick="window.location.reload();">Refresh</button>

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

</body>
</html>