0% found this document useful (0 votes)
51 views4 pages

Django Template and URL Setup Guide

The document discusses creating templates, views, and URL mapping in Django. It shows how to define templates and settings, render templates from views, pass variables to templates, and map URLs to views using regular expressions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views4 pages

Django Template and URL Setup Guide

The document discusses creating templates, views, and URL mapping in Django. It shows how to define templates and settings, render templates from views, pass variables to templates, and map URLs to views using regular expressions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Python – FullStack

Creating Templates:
**********************
[Link]

TEMPLATES = [
{
'BACKEND': '[Link]',
'DIRS': [[Link](BASE_DIR,'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'[Link].context_processors.debug',
'[Link].context_processors.request',
'[Link].context_processors.auth',
'[Link].context_processors.messages',
],
},
},
]

[Link]:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
<h2>Welcome to Django!!!</h2>
</body>
</html>
[Link]

from [Link] import render


#importing loading from django template
from [Link] import loader
# Create your views here.
from [Link] import HttpResponse
def index(request):
template = loader.get_template('[Link]') # getting our template
return HttpResponse([Link]()) # rendering the template in

Django Variables Example:

[Link]:

from [Link] import render


#importing loading from django template
from [Link] import loader
# Create your views here.
from [Link] import HttpResponse
def index(request):
template = loader.get_template('[Link]') # getting our template
name = {
'student':'rahul'
}
return HttpResponse([Link](name)) # rendering the template in
HttpResponse

[Link]:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
<h2>Welcome to Django!!!</h2>
<h3>My Name is: {{ student }}</h3>
</body>
</html>

*************************8

Tags:

{% csrf_token %}

{% if user.is_authenticated %}
Hello, {{ [Link] }}.
{% endif %}

*********************************************

Django URL Mapping:

[Link]:

from [Link] import admin


from [Link] import path

urlpatterns = [
path('admin/', [Link]),
]
Django URL Mapping:

// [Link]

from [Link] import render


# Create your views here.
from [Link] import HttpResponse, HttpResponseNotFound
from [Link] import require_http_methods
@require_http_methods(["GET"])
def hello(request):
return HttpResponse('<h1>This is Http GET request.</h1>')

//[Link]

from [Link] import admin


from [Link] import path
from myapp import views
urlpatterns = [
path('admin/', [Link]),
path('index/', [Link]),
path('hello/', [Link]),
]

You might also like