Skip to content

Instantly share code, notes, and snippets.

@sivaa
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivaa/bf2fdcba25803da6f04b to your computer and use it in GitHub Desktop.
Save sivaa/bf2fdcba25803da6f04b to your computer and use it in GitHub Desktop.
#### Step 0: Installtion/Setup ####
Microsoft Windows 7 : http://bit.ly/pycon-gswd-windows-setup
GNU/Linux Ubuntu : http://bit.ly/pycon-gswd-linux-setup
GNU/Linux CentOS : http://bit.ly/pycon-gswd-centos-setup
# Once the above setup is done, pull the latest content from the repository
git pull
#### Step 1: Django Project Creation ####
# [OPTIONAL] Checkout the base branch for this rampup excercise
git checkout rampup_base
# Create a project using the following command
# Windows :
python C:\Users\<User name>\Envs\pycon-dj-workshop\Scripts\django-admin.py startproject fav
# Linux
python ~/.virtualenvs/pycon-dj-workshop/bin/django-admin.py startproject fav
# List the created new files
# Windows:
tree /F
# Linux:
tree
# Navigate to the project directory
cd fav
# Refer the settings (INSTALLED_APPS and DATABASES)
# Create the necessary tables for the INSTALLED_APPS
python manage.py syncdb
# Choose 'No' for super user creation
# Run the development server
python manage.py runserver
# Verify it in the browser (http://localhost:8000)
# Create a demo app
python manage.py startapp demo
# List the created new files using tree command
#### Step 2: Simple Hello World ####
# Open fav/demo/views.py and create a view for returning "Hello World!" as a HTTP response
from django.http import HttpResponse
def hello1(request):
return HttpResponse("Hello World!")
# Open fav/fav/urls.py and create a routing for the above view
url(r'^hello1/', 'demo.views.hello1'),
# Make sure that the dev server is running and access the following URL in the browser
http://localhost:8000/hello1/
# Write a another view to return the HTML string as a HTTP response
def hello2(request):
return HttpResponse("<h1>Hello World!</h1>")
# Create a routing for the above view in urls.py
url(r'^hello2/', 'demo.views.hello2'),
# Access the following URL in the browser
http://localhost:8000/hello2/
# Write a another view to return the currnet timestamp
from datetime import datetime
def hello3(request):
return HttpResponse("<h1>Hello World! at {} </h1>".format(datetime.now()))
# Create a routing for the above view in urls.py
url(r'^hello3/', 'demo.views.hello3'),
# Access the following URL in the browser
http://localhost:8000/hello3/
# Write a another view to fetch and retrun the query string
def hello4(request):
name = request.GET.get("name", "Django")
return HttpResponse("Hello <strong>{}</strong>!".format(name)))
# Create a routing for the above view in urls.py
url(r'^hello4/', 'demo.views.hello4'),
# Access the following URLs in the browser
http://localhost:8000/hello4/
http://localhost:8000/hello4/?name=Siva
#### Step 3: Hello World with Templates ####
# Create a 'templates' directory under fav/demo/ folder
mkdir demo/templates
# Create a HTML document called 'hello5.html' with the following content
<!DOCTYPE html>
<html>
<head>
<title>Introduction to Django Workshop</title>
</head>
<body>
Hello World!
</body>
</html>
# Write a another view to return the above template as a HTTP response
from django.shortcuts import render
def hello5(request):
return render(request, "hello5.html")
# Create a routing for the above view in urls.py
url(r'^hello5/', 'demo.views.hello5'),
# Access the following URL in the browser
http://localhost:8000/hello5/
# It will throw the TemplateDoesNotExist exception since this app is not registred.
# Registred this app in the INSTALLED_APPS tuple in fav/fav/settings.py
'demo',
# Try the same url again in the browser
# Copy the 'hello5.html and create hello6.html' and update the body with current_time template variable
<body>
Hello World! at {{ current_time }}
</body>
# Write a another view to return the currnet timestamp
def hello6(request):
return render(request,
"hello6.html",
{'current_time' : datetime.now() })
# Create a routing for the above view in urls.py
url(r'^hello6/', 'demo.views.hello6'),
# Access the following URL in the browser
http://localhost:8000/hello6/
# Copy the 'hello5.html and create hello7.html' and update the body with name template variable
<body>
Hello <strong> {{ name }} <strong>!
</body>
# Write a another view to fetch and retrun the query string
def hello7(request):
name = request.GET.get("name", "Django")
return render(request,
"hello7.html",
{'name' : name })
# Create a routing for the above view in urls.py
url(r'^hello7/', 'demo.views.hello7'),
# Access the following URLs in the browser
http://localhost:8000/hello7/
http://localhost:8000/hello7/?name=Siva
# [OPTIONAL] Checkout the complete branch for this rampup excercise to for reference
git checkout rampup_complete
@muke5hy
Copy link

muke5hy commented Sep 25, 2014

In rampup_base branch there is no code.

@sivaa
Copy link
Author

sivaa commented Feb 19, 2015

Yep. Its a scratch space. Checkout 'rampup_complete' for code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment