Skip to content

Commit

Permalink
Using the messages framework
Browse files Browse the repository at this point in the history
  • Loading branch information
yahyaaly151989 committed Sep 23, 2023
1 parent c2f7847 commit 1f2763b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
Binary file modified Module04/bookmarks/account/__pycache__/views.cpython-311.pyc
Binary file not shown.
11 changes: 10 additions & 1 deletion Module04/bookmarks/account/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@
</span>

</div>

{% if messages %}
<ul class="messages">
{% for message in messages %}
<li class="{{message.tags}}">
{{message|safe}}
</li>
<a href="#" class="close">X</a>
{% endfor %}
</ul>
{% endif %}
<div id="content">
{% block content %} {% endblock %}
</div>
Expand Down
5 changes: 5 additions & 0 deletions Module04/bookmarks/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from .models import Profile
from django.contrib import messages

# def user_login(request):
# if request.method == 'POST':
Expand Down Expand Up @@ -48,6 +49,10 @@ def edit(request):
if user_form.is_valid() and profile_form.is_valid():
user_form.save()
profile_form.save()
messages.success(request, 'Profile has been updated successfully.')
else:
messages.error(request, 'Error updaing your profile.')

else:
user_form = UserEditForm(instance=request.user)
profile_form = ProfileEditForm(instance=request.user.profile)
Expand Down
Binary file modified Module04/bookmarks/db.sqlite3
Binary file not shown.

0 comments on commit 1f2763b

Please sign in to comment.