diff --git a/django_project/settings.py b/django_project/settings.py index 85d47deb..cfdaff28 100644 --- a/django_project/settings.py +++ b/django_project/settings.py @@ -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 @@ -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 @@ -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 diff --git a/django_project/urls.py b/django_project/urls.py index ece665e5..9e9c8c19 100644 --- a/django_project/urls.py +++ b/django_project/urls.py @@ -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'), + + ] diff --git a/django_project/views.py b/django_project/views.py index f9042b4c..0e844299 100644 --- a/django_project/views.py +++ b/django_project/views.py @@ -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}) \ No newline at end of file diff --git a/static/styles.css b/static/styles.css index 530d510b..1a95b0ff 100644 --- a/static/styles.css +++ b/static/styles.css @@ -2,6 +2,10 @@ body{ background: hotpink } +h1{ + align-items: center; +} + img{ width: 100px; height: 100px; diff --git a/templates/index.html b/templates/index.html index b0f60817..cdc94f44 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,22 +1,34 @@ -{% load static%} +{% load static %}
+