Skip to content

Commit

Permalink
Templates and views restructer for better accesibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ZEZE1020 committed Jan 13, 2025
1 parent db76ae3 commit df868c1
Show file tree
Hide file tree
Showing 22 changed files with 93 additions and 54 deletions.
File renamed without changes.
8 changes: 8 additions & 0 deletions accounts/templates/logout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends 'base.html' %}

{% block title %}Logout{% endblock %}

{% block content %}
<h2>You have been logged out.</h2>
<p><a href="{% url 'home' %}">Return to Home</a></p>
{% endblock %}
20 changes: 20 additions & 0 deletions accounts/templates/profile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Profile</title>
{% load static %}
<link rel="stylesheet" href="{% static 'accounts/styles.css' %}">
</head>
<body>
<header>
<h1>{{ user.username }}'s Profile</h1>
</header>
<main>
<p>Email: {{ user.email }}</p>
<p>First Name: {{ user.first_name }}</p>
<p>Last Name: {{ user.last_name }}</p>
</main>
</body>
</html>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 14 additions & 6 deletions accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@
from .models import CustomUser, Follow, Post
from .forms import CustomUserCreationForm, CustomUserChangeForm
from django.shortcuts import render
from django.shortcuts import render
from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import logout


def home(request):
return render(request, 'home.html')



def accounts_home(request):
return redirect('login') # Redirects to the login page


def home(request):
return render(request, 'home.html')

Expand Down Expand Up @@ -71,7 +77,7 @@ def user_profile(request, user_id):
'followers': followers,
'following': following,
}
return render(request, 'accounts/profile.html', context)
return render(request, 'accounts/profile.html', {'user': user})

def login_view(request):
form = AuthenticationForm(data=request.POST or None)
Expand All @@ -80,14 +86,16 @@ def login_view(request):
login(request, user)
next_url = request.GET('next', 'home')
return redirect('home')

return render(request, 'login.html', {'form': form})


def logout_view(request):
if request.method == 'POST':
logout(request)
def logout_view(request):
if request.method == 'POST':
logout(request)
return redirect('home')
else:
return redirect('home') # Redirect to home if not POST request



def signup(request):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified social_media_api/__pycache__/settings.cpython-313.pyc
Binary file not shown.
10 changes: 7 additions & 3 deletions social_media_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['social-media-api-a5m3.onrender.com', '127.0.0.1:8000']
ALLOWED_HOSTS = [
'localhost',
'127.0.0.1',
'social-media-api-a5m3.onrender.com',
]


# Application definition
Expand Down Expand Up @@ -122,8 +126,8 @@
# settings.py


DATABASES = {
'default': dj_database_url.config(conn_max_age=600)
DATABASES = {
'default': dj_database_url.config(default=config('DATABASE_URL'))
}


Expand Down
3 changes: 1 addition & 2 deletions social_media_api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
path('api/accounts/', include('accounts.urls')),
path('api/notifications/', include('notifications.urls')),
path('api/posts/', include('posts.urls')),
path('', home_view, name='home'),
path('accounts', include('allauth.urls'))
path('accounts', include('allauth.urls')),
]

if settings.DEBUG:
Expand Down
32 changes: 32 additions & 0 deletions staticfiles/home/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f9f9f9;
}

header {
background-color: #333;
color: #fff;
padding: 1em;
text-align: center;
}

h1 {
color: #333;
}

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

nav li {
display: inline;
margin-right: 1em;
}

nav a {
color: #fff;
text-decoration: none;
}
39 changes: 0 additions & 39 deletions templates/accounts/profile.html

This file was deleted.

15 changes: 11 additions & 4 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@
<li><a href="/api/accounts/">Accounts API</a></li>
<li><a href="/api/notifications/">Notifications API</a></li>
<li><a href="/api/posts/">Posts API</a></li>
<li><a href="/accounts/">Accounts</a></li>
{% if user.is_authenticated %}
<li><a href="{% url 'logout' %}">Sign Out</a></li>
<li>
<form action="{% url 'logout' %}" method="post" style="display:inline;">
{% csrf_token %}
<button type="submit" style="background:none; border:none; color:inherit; cursor:pointer; font:inherit; padding:0;">Sign Out</button>
</form>
</li>
{% else %}
<li><a href="{% url 'signup' %}">Sign Up</a></li>
<li><a href="{% url 'login' %}">Sign In</a></li>
Expand All @@ -40,9 +44,12 @@
<li><a href="/api/accounts/">Accounts API</a></li>
<li><a href="/api/notifications/">Notifications API</a></li>
<li><a href="/api/posts/">Posts API</a></li>
<li><a href="/accounts/">Accounts</a></li>
{% if user.is_authenticated %}
<li><a href="{% url 'logout' %}">Sign Out</a></li>
<form action="{% url 'logout' %}" method="post" style="display:inline;">
{% csrf_token %}
<button type="submit" style="background:none; border:none; color:inherit; cursor:pointer; font:inherit; padding:0;">Sign Out</button>
</form>
</li>
{% else %}
<li><a href="{% url 'signup' %}">Sign Up</a></li>
<li><a href="{% url 'login' %}">Sign In</a></li>
Expand Down

0 comments on commit df868c1

Please sign in to comment.