-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviews.py
35 lines (29 loc) · 1.09 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import requests
from django.http import HttpResponse
from django.shortcuts import render
def index(request):
# This is similar to ones we have done before. Instead of keeping
# the HTML / template in a separate directory, we just reply with
# the HTML embedded here.
return HttpResponse('''
<h1>Welcome to my home page!</h1>
<a href="/about-me">About me</a> <br />
<a href="/github-api-example">See my GitHub contributions</a> <br />
''')
def about_me(request):
# Django comes with a "shortcut" function called "render", that
# lets us read in HTML template files in separate directories to
# keep our code better organized.
context = {
'name': 'Ash Ketchum',
'pokemon': 'Pikachu',
}
return render(request, 'about_me.html', context)
def github_api_example(request):
# We can also combine Django with APIs
response = requests.get('https://api.github.com/users/kickstartcoding/repos')
repos = response.json()
context = {
'github_repos': repos,
}
return render(request, 'github.html', context)