Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- # views.py
- from django.shortcuts import render
- def error_403(request, exception):
- return render(request, '403.html', status=403)
- # urls.py
- from django.urls import path, include
- from .views import error_403
- urlpatterns = [
- # your other paths
- ]
- handler403 = 'my_holiday.destination.views.error_403'
- 2.
- <!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">
- <title>Forbidden (403)</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- background-color: #f0f0f0;
- text-align: center;
- padding: 50px;
- }
- h1 {
- color: #ff0000; /* Change color to red */
- }
- img {
- max-width: 100%;
- height: auto;
- margin-bottom: 20px;
- }
- </style>
- </head>
- <body>
- <h1>{{ message }}</h1>
- <img src="{% static 'images/403-status-code.png' %}" alt="Forbidden">
- </body>
- </html>
- 3.
- from django.http import HttpResponseForbidden
- @method_decorator(login_required, name='dispatch')
- class PlaceEditView(views.UpdateView):
- queryset = Place.objects.all()
- template_name = "destination/place_edit.html"
- form_class = PlaceEditForm
- success_url = reverse_lazy('travelogue_view')
- def dispatch(self, request, *args, **kwargs):
- obj = self.get_object()
- if obj.user != self.request.user:
- return HttpResponseForbidden("You do not have permission to edit this place.")
- return super().dispatch(request, *args, **kwargs)
- @method_decorator(login_required, name='dispatch')
- class PlaceDeleteView(views.DeleteView):
- queryset = Place.objects.all()
- template_name = "destination/place_delete.html"
- success_url = reverse_lazy('travelogue_view')
- def dispatch(self, request, *args, **kwargs):
- obj = self.get_object()
- if obj.user != self.request.user:
- return HttpResponseForbidden("You do not have permission to delete this place.")
- return super().dispatch(request, *args, **kwargs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement