Skip to content

Commit 4fb6199

Browse files
committed
Add README.md and requirements.txt
Fix sample code to be in line with changes in article
1 parent ab98050 commit 4fb6199

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

django-view-auth/Blog/core/views.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.contrib import messages
2-
from django.contrib.auth.decorators import login_required, user_passes_test
2+
from django.contrib.auth.decorators import login_required
33
from django.http import HttpResponse
44
from django.shortcuts import render, get_object_or_404
55
from core.models import Blog
@@ -29,8 +29,8 @@ def see_request(request):
2929
scheme: {request.scheme}
3030
path: {request.path}
3131
method: {request.method}
32-
GET: {request.GET}
33-
user: {request.user}
32+
GET: {request.GET}
33+
user: {request.user}
3434
"""
3535

3636
return HttpResponse(text, content_type="text/plain")
@@ -55,6 +55,8 @@ def private_place(request):
5555
return HttpResponse("Shhh, members only!", content_type="text/plain")
5656

5757

58+
from django.contrib.auth.decorators import user_passes_test
59+
5860
@user_passes_test(lambda user: user.is_staff)
5961
def staff_place(request):
6062
return HttpResponse("Employees must wash hands", content_type="text/plain")

django-view-auth/Blog/db.sqlite3

-132 KB
Binary file not shown.

django-view-auth/Blog/pyflakes.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

django-view-auth/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Get Started With Django Part 3: Django View Authorization, Code Examples
2+
3+
This folder contains the sample code for [Get Started With Django Part 3: Django View Authorization](https://realpython.com/django-view-authorization/).
4+
5+
The code was tested with Python 3.8 and Django 3.0.7. To install the same version, use:
6+
7+
python -m pip install -r requirements.txt
8+
9+
This tutorial uses the Django admin, and comes with some sample data. To get going you will need to run the following commands:
10+
11+
cd Blog
12+
python manage.py migrate
13+
python manage.py createsuperuser
14+
python manage.py loaddata core.json
15+
16+
Once those commands are complete, you can run the Django development server:
17+
18+
python manage.py runserver
19+
20+
With the server running, visit `http://127.0.0.1:8000` in your web browser to see the results.

django-view-auth/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Django==3.0.7

0 commit comments

Comments
 (0)