Django Tutorial With Template

Today I have learn how to work with Templates in django.

Now start  the work on templates first set is create static pages in Django.

1) open your settings file (

2)Find this line in if this exits then is ok otherwise add this in file STATIC_URL = ‘/static/’

3) Add this settings for template files

 os.path.join(os.path.dirname(BASE_DIR), "/home/sofat/static", "mytemplate"),

4)Now create static directory and inner of this create mytemplate directory

5) Now open your file and set your Static page as HomePage.

from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = patterns('',
# Examples:
url(r'^$', 'signUp.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(,

6) Open you view file to connect your view with your static page

from django.shortcuts import render, render_to_response, RequestContext, HttpResponseRedirect
from django.contrib import messages
from .forms import SignUpForm
def home(request):

form = SignUpForm(request.POST or None)
if form.is_valid():
save_it =
messages.success(request, 'Thanks for Register')
return HttpResponseRedirect('/thank-you/')

return render_to_response("signup.html",locals(),context_instance = RequestContext(request))

def thankyou(request):
return render_to_response("thankyou.html",locals(),context_instance = RequestContext(request))

7)Now create new html page and save in static/mytemplate

8) Run your code

python runserver


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s