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: 5 additions & 0 deletions .replit
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ deploymentTarget = "gce"

[[ports]]
localPort = 3000
externalPort = 3000

[[ports]]
localPort = 8000
externalPort = 80
exposeLocalhost = true
31 changes: 26 additions & 5 deletions 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 All @@ -23,7 +24,7 @@
SECRET_KEY = 'django-insecure-4ju2n@$f9d0c=h)_g0lbb%k9&@rf(xa$d$g$&5ri$uf)*gev^4'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = False

ALLOWED_HOSTS = [".replit.dev", ".replit.app"]
CSRF_TRUSTED_ORIGINS = ["https://*.replit.dev", "https://*.replit.app"]
Expand All @@ -37,6 +38,8 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myblog',
'weatherapp'
]

MIDDLEWARE = [
Expand All @@ -51,7 +54,7 @@

ROOT_URLCONF = 'django_project.urls'

TEMPLATES = [
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR],
Expand Down Expand Up @@ -85,8 +88,8 @@
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
{'NAME':'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'
,
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
Expand Down Expand Up @@ -117,9 +120,27 @@

STATIC_URL = 'static/'

'''STATICFILES_DIRS = [
BASE_DIR / 'static','''



STATIC_ROOT = BASE_DIR / 'staticfiles'



STATICFILES_DIRS = [
BASE_DIR / 'static',
BASE_DIR / 'static',
BASE_DIR / 'staticweather',
]
#('myblog', os.path.join(BASE_DIR, 'myblog', 'static')),'''



STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
)

# Default primary key field type
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field

Expand Down
11 changes: 9 additions & 2 deletions django_project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@
"""
from django.contrib import admin
from django.urls import path

from django.conf import settings
from django.conf.urls.static import static

from . import views


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

from weatherapp import views
urlpatterns += [path('weather/',views.weather, name='weather')]

1 change: 1 addition & 0 deletions django_project/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
from django.shortcuts import render
from weatherapp.views import weather

def home(request):
# USING APIS => Example 1
Expand Down
4 changes: 4 additions & 0 deletions httpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Alias /static/ /path/to/your/STATIC_ROOT/
<Directory /path/to/your/STATIC_ROOT/>
Require all granted
</Directory>
Empty file modified manage.py
100644 → 100755
Empty file.
Empty file added myblog/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions myblog/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from django.contrib import admin
from .models import Post
# Register your models here.
admin.site.register(Post)
6 changes: 6 additions & 0 deletions myblog/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class MyblogConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'myblog'
38 changes: 38 additions & 0 deletions myblog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Generated by Django 5.0.2 on 2024-05-13 10:00

import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Post',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True,
serialize=False,
verbose_name='ID')),
('title', models.CharField(max_length=250)),
('slug', models.SlugField(max_length=250)),
('body', models.TextField()),
('publish', models.DateTimeField(default=django.utils.timezone.now)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('status', models.CharField(choices=[('DF', 'Draft'),
('PB', 'Published')],
default='DF', max_length=2)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
related_name
=' blog_posts', to=settings.AUTH_USER_MODEL)),
],
),
]
21 changes: 21 additions & 0 deletions myblog/migrations/0002_alter_post_author.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 5.0.2 on 2024-05-14 09:22

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('myblog', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AlterField(
model_name='post',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='blog_posts', to=settings.AUTH_USER_MODEL),
),
]
Empty file added myblog/migrations/__init__.py
Empty file.
32 changes: 32 additions & 0 deletions myblog/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.utils import timezone
from django.db import models
from django.contrib.auth.models import User

# Create your models here.
class Post(models.Model):

class Status(models.TextChoices):
DRAFT = 'DF', 'Draft'
PUBLISHED = 'PB', 'Published'

title = models.CharField(max_length=250)
slug = models.SlugField(max_length=250)
author = models.ForeignKey(User,
on_delete=models.CASCADE,
related_name='blog_posts')
body = models.TextField()
publish = models.DateTimeField(default=timezone.now)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
status = models.CharField(max_length=2,
choices=Status.choices,
default=Status.DRAFT)

class Meta:
ordering = ['-publish']
indexes = [
models.Index(fields=['-publish']),
]

def __str__(self):
return self.title
3 changes: 3 additions & 0 deletions myblog/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions myblog/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
5 changes: 5 additions & 0 deletions replit.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{pkgs}: {
deps = [
pkgs.lsof
];
}
39 changes: 39 additions & 0 deletions staticweather/weather.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

body{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
justify-content: center;
align-items: center;
min-height: 100vh;
background-image: linear-gradient(to right, #0f0c29, #302b63, #24243e);
background-repeat: no-repeat;
}

h1{
color: #66fcf1;
margin-bottom: 50px;
}

/* .weather-box{
background-color: rgba(0, 156, 255, 0.4);
padding: 20px;
border-radius: 10px;
border: none;
}

.weather-box span{
font-size: 15px;
}

.weather-box h2{
margin-top: 10px;
margin-bottom: 0;
}

.weather-box hr{
height: 1px;
color: #fff;
background-color: #fff;
border: none;
width: 80%;
margin-bottom: 20px;
} */
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load static%}
{% load static from static%}
<!DOCTYPE html>
<html lang="en">
<head>
Expand Down
33 changes: 33 additions & 0 deletions templatesweather/weather.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% load static from staticweather%}
<!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="{% staticweather 'css/weather.css' %}" />
<!-- <link rel="stylesheet" href="/static/styles.css" /> -->
<title>Document</title>
</head>
<body>
<h1>MY WEATHER TODAY </h1>


<h1>Today's weather</h1>
{{result3}}


<!-- <div class="weather-box">
<h2>{{result3['name']}}</h2>
<p>
<span>{{result3['main']['feels_like']}}°F</span>
<span>{{result3['weather'][0]['description']}}</span>
</p>
<hr>
<p>Humidity: {{result3['main']['humidity']}}%</p>
<p>Wind Speed: {{result3['wind']['speed']}} mph</p>
</div> -->


</body>
</html>
Empty file added weatherapp/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions weatherapp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
13 changes: 13 additions & 0 deletions weatherapp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.apps import AppConfig




class WeatherappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'weatherapp'


def ready(self):
from .templates import register_templates
register_templatesweather(weather.html)
Empty file.
3 changes: 3 additions & 0 deletions weatherapp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions weatherapp/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
12 changes: 12 additions & 0 deletions weatherapp/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

from django.urls import path

from weatherapp import views

app_name = 'weatherapp'

urlpatterns = [
# path('index/', views.index, name='index'),
path('', views.weather, name='weather'),

]
15 changes: 15 additions & 0 deletions weatherapp/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


import requests
import json
from django.shortcuts import render


def weather(request):
response = requests.get('https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid=66048f26223dbab85dbd25354dc61f58')
data = response.json()
result3 = data ['icon']

return render(request, 'templatesweather/weather.html',{'result3':result3})
# Create your views here.