Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code updates #215

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'blog.apps.BlogConfig',
'users.apps.UsersConfig',
'crispy_forms',
'crispy_bootstrap5',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -122,4 +123,5 @@

STATIC_URL = '/static/'

CRISPY_TEMPLATE_PACK = 'bootstrap4'
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'blog.apps.BlogConfig',
'users.apps.UsersConfig',
'crispy_forms',
'crispy_bootstrap5',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -125,7 +126,8 @@
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

CRISPY_TEMPLATE_PACK = 'bootstrap4'
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"

LOGIN_REDIRECT_URL = 'blog-home'
LOGIN_URL = 'login'
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
path('register/', user_views.register, name='register'),
path('profile/', user_views.profile, name='profile'),
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
path('logout/', user_views.logout_view, name="logout"),
path('', include('blog.urls')),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from .forms import UserRegisterForm
from django.contrib.auth import logout


def register(request):
Expand All @@ -17,6 +18,11 @@ def register(request):
return render(request, 'users/register.html', {'form': form})


def logout_view(request):
logout(request)
return render(request, 'users/logout.html')


@login_required
def profile(request):
return render(request, 'users/profile.html')
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'blog.apps.BlogConfig',
'users.apps.UsersConfig',
'crispy_forms',
'crispy_bootstrap5',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -125,7 +126,8 @@
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

CRISPY_TEMPLATE_PACK = 'bootstrap4'
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"

LOGIN_REDIRECT_URL = 'blog-home'
LOGIN_URL = 'login'
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
path('register/', user_views.register, name='register'),
path('profile/', user_views.profile, name='profile'),
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
path('logout/', user_views.logout_view, name="logout"),
path('', include('blog.urls')),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from .forms import UserRegisterForm

from django.contrib.auth import logout

def register(request):
if request.method == 'POST':
Expand All @@ -17,6 +17,11 @@ def register(request):
return render(request, 'users/register.html', {'form': form})


def logout_view(request):
logout(request)
return render(request, 'users/logout.html')


@login_required
def profile(request):
return render(request, 'users/profile.html')
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ a.article-title:hover {
}

.article-img {
height: 65px;
width: 65px;
height: 90px;
width: 90px;
margin-right: 16px;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
{% extends "blog/base.html" %}
{% extends "blog/base.html"%}
{% block content %}
{% for post in posts %}
<article class="media content-section">
<img class="rounded-circle article-img" src="{{ post.author.profile.image.url }}">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="#">{{ post.author }}</a>
<small class="text-muted">{{ post.date_posted|date:"F d, Y" }}</small>
</div>
<h2><a class="article-title" href="#">{{ post.title }}</a></h2>
<p class="article-content">{{ post.content }}</p>
</div>
</article>
{% endfor %}
{% for post in posts %}
<article class="media content-section mt-2">
<div class="row">
<div class="col-auto mt-2">
<img class="rounded-circle article-img" src="{{ post.author.profile.image.url }}">
</div>
<div class="media-body col-auto">
<div class="article-metadata">
<a style="text-decoration: none;" class="mr-2" href="#">{{ post.author }}</a>
<small class="text-muted">{{ post.date_posted|date:"F d, Y" }}</small>
</div>
<h2><a style="text-decoration: none;" class="article-title" href="#">{{ post.title }}</a></h2>
<p class="article-content">{{ post.content }}</p>
</div>
</div>

</article>
{% endfor %}
{% endblock content %}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'blog.apps.BlogConfig',
'users.apps.UsersConfig',
'crispy_forms',
'crispy_bootstrap5',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -125,7 +126,8 @@
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

CRISPY_TEMPLATE_PACK = 'bootstrap4'
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"

LOGIN_REDIRECT_URL = 'blog-home'
LOGIN_URL = 'login'
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
path('register/', user_views.register, name='register'),
path('profile/', user_views.profile, name='profile'),
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
path('logout/', user_views.logout_view, name="logout"),
path('', include('blog.urls')),
]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
{% extends "blog/base.html" %}
{% load crispy_forms_tags %}

{% block content %}

<div class="content-section">
<div class="media">
<img class="rounded-circle account-img" src="{{ user.profile.image.url }}">
<div class="media-body">
<h2 class="account-heading">{{ user.username }}</h2>
<p class="text-secondary">{{ user.email }}</p>

<div class="media row">
<div class="col-lg-3 col-md-6 col-sm-6">
<img class="rounded-circle account-img " src="{{ user.profile.image.url }}">
</div>
<div class="media-body col-lg-3 col-md-6 col-sm-6">
<h2 class="account-heading mt-4">{{user.username}}</h2>
<p class="text-secondary mt-2">{{user.email}}</p>
</div>
</div>
</div>
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4">Profile Info</legend>
{{ u_form|crispy }}
{{ p_form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Update</button>
</div>
</form>

<!-- FORM HERE -->
<form method="POST", enctype="multipart/form-data"> <!-- remember enctype -->
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-4 mt-2"> Profile Info </legend>
{{ u_form|crispy }}
{{ p_form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit"> Update </button>
</div>
</form>
</div>

{% endblock content %}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from .forms import UserRegisterForm, UserUpdateForm, ProfileUpdateForm

from django.contrib.auth import logout

def register(request):
if request.method == 'POST':
Expand All @@ -16,6 +16,10 @@ def register(request):
form = UserRegisterForm()
return render(request, 'users/register.html', {'form': form})

def logout_view(request):
logout(request)
return render(request, 'users/logout.html')


@login_required
def profile(request):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'blog.apps.BlogConfig',
'users.apps.UsersConfig',
'crispy_forms',
'crispy_bootstrap5',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -125,7 +126,9 @@
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

CRISPY_TEMPLATE_PACK = 'bootstrap4'
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"


LOGIN_REDIRECT_URL = 'blog-home'
LOGIN_URL = 'login'
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
path('register/', user_views.register, name='register'),
path('profile/', user_views.profile, name='profile'),
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
path('logout/', user_views.logout_view, name="logout"),
path('', include('blog.urls')),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from .forms import UserRegisterForm, UserUpdateForm, ProfileUpdateForm
from django.contrib.auth import logout


def register(request):
Expand All @@ -17,6 +18,11 @@ def register(request):
return render(request, 'users/register.html', {'form': form})


def logout_view(request):
logout(request)
return render(request, 'users/logout.html')


@login_required
def profile(request):
if request.method == 'POST':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'blog.apps.BlogConfig',
'users.apps.UsersConfig',
'crispy_forms',
'crispy_bootstrap5',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
Expand Down Expand Up @@ -125,7 +126,9 @@
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

CRISPY_TEMPLATE_PACK = 'bootstrap4'
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"
CRISPY_TEMPLATE_PACK = "bootstrap5"


LOGIN_REDIRECT_URL = 'blog-home'
LOGIN_URL = 'login'
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
path('register/', user_views.register, name='register'),
path('profile/', user_views.profile, name='profile'),
path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
path('logout/', user_views.logout_view, name="logout"),
path('', include('blog.urls')),
]

Expand Down
7 changes: 6 additions & 1 deletion Django_Blog/11-Pagination/django_project/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from .forms import UserRegisterForm, UserUpdateForm, ProfileUpdateForm

from django.contrib.auth import logout

def register(request):
if request.method == 'POST':
Expand All @@ -17,6 +17,11 @@ def register(request):
return render(request, 'users/register.html', {'form': form})


def logout_view(request):
logout(request)
return render(request, 'users/logout.html')


@login_required
def profile(request):
if request.method == 'POST':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<nav class="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
<div class="container">
<a class="navbar-brand mr-4" href="{% url 'blog-home' %}">Django Blog</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle" aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarToggle" aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarToggle">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
{% block content %}
{% for post in posts %}
<article class="media content-section">
<img class="rounded-circle article-img" src="{{ post.author.profile.image.url }}">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="{% url 'user-posts' post.author.username %}">{{ post.author }}</a>
<small class="text-muted">{{ post.date_posted|date:"F d, Y" }}</small>
<div class="row ">
<div class="col-xl-2 col-md-4 col-lg-3">
<img class="rounded-circle article-img" src="{{ post.author.profile.image.url }}">
</div>
<div class="media-body col-xl-10 col-md-8 col-lg-9">
<div class="article-metadata">
<a class="mr-2" href="{% url 'user-posts' post.author.username %}">{{ post.author }}</a>
<small class="text-muted">{{ post.date_posted|date:"F d, Y" }}</small>
</div>
<h2><a class="article-title" href="{% url 'post-detail' post.id %}">{{ post.title }}</a></h2>
<p class="article-content">{{ post.content }}</p>
</div>
<h2><a class="article-title" href="{% url 'post-detail' post.id %}">{{ post.title }}</a></h2>
<p class="article-content">{{ post.content }}</p>
</div>
</article>
{% endfor %}
<div class="container text-center">
{% if is_paginated %}

{% if page_obj.has_previous %}
Expand All @@ -34,4 +39,5 @@ <h2><a class="article-title" href="{% url 'post-detail' post.id %}">{{ post.titl
{% endif %}

{% endif %}
</div>
{% endblock content %}
Loading