aboutsummaryrefslogtreecommitdiff
path: root/userpages
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-08-02 20:19:26 +0530
committerBobby <[email protected]>2022-08-02 20:19:26 +0530
commit73a7b9e9a493951926b64f55fa25f075577812a9 (patch)
treeb478cac93d710b0512cafc714dbe66b8252abac8 /userpages
parentd08afc2e7e8f699d00c8b254cbe1f83b845c70bb (diff)
downloadthatcomputerscientist-73a7b9e9a493951926b64f55fa25f075577812a9.tar.xz
thatcomputerscientist-73a7b9e9a493951926b64f55fa25f075577812a9.zip
Added exception handling for user subdomains
Diffstat (limited to 'userpages')
-rw-r--r--userpages/views.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/userpages/views.py b/userpages/views.py
index be0de840..11b2fce7 100644
--- a/userpages/views.py
+++ b/userpages/views.py
@@ -1,6 +1,23 @@
from django.shortcuts import render
-from django.http import HttpResponse
+from django.http import HttpResponse, Http404
+from users.models import UserProfile
+from django.contrib.auth.models import User
# Create your views here.
def home(request):
- return HttpResponse('Hello, world. You are at the home page.')
+ subdomain = request.subdomain
+ try:
+ user = User.objects.get(username=subdomain)
+ try:
+ user_profile = UserProfile.objects.get(user=user)
+ is_public = user_profile.is_public
+ if is_public:
+ return HttpResponse('Welcome to {}\'s homepage!'.format(subdomain))
+ else:
+ raise Http404('{} is not public.'.format(subdomain))
+ except UserProfile.DoesNotExist:
+ raise Http404('{} has no profile.'.format(subdomain))
+
+ except User.DoesNotExist:
+ raise Http404('{} does not exist.'.format(subdomain))
+