<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Python-Django%2FC2%2FCreating-Views-and-Designing-URLs%2FEnglish</id>
		<title>Python-Django/C2/Creating-Views-and-Designing-URLs/English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=Python-Django%2FC2%2FCreating-Views-and-Designing-URLs%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python-Django/C2/Creating-Views-and-Designing-URLs/English&amp;action=history"/>
		<updated>2026-04-05T20:22:59Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Python-Django/C2/Creating-Views-and-Designing-URLs/English&amp;diff=44342&amp;oldid=prev</id>
		<title>Nancyvarkey at 12:23, 13 September 2018</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python-Django/C2/Creating-Views-and-Designing-URLs/English&amp;diff=44342&amp;oldid=prev"/>
				<updated>2018-09-13T12:23:39Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;https://script.spoken-tutorial.org/index.php?title=Python-Django/C2/Creating-Views-and-Designing-URLs/English&amp;amp;diff=44342&amp;amp;oldid=44303&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Nancyvarkey</name></author>	</entry>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=Python-Django/C2/Creating-Views-and-Designing-URLs/English&amp;diff=44303&amp;oldid=prev</id>
		<title>Pravin1389: Created page with &quot;'''Title of script:'''Creating Views and Design URLs  '''Keywords: '''Video tutorial, Django view, URL routing scheme  {| border=1 |- || '''Visual cue''' || '''Narration''' |-...&quot;</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=Python-Django/C2/Creating-Views-and-Designing-URLs/English&amp;diff=44303&amp;oldid=prev"/>
				<updated>2018-09-06T16:23:31Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;#039;&amp;#039;&amp;#039;Title of script:&amp;#039;&amp;#039;&amp;#039;Creating Views and Design URLs  &amp;#039;&amp;#039;&amp;#039;Keywords: &amp;#039;&amp;#039;&amp;#039;Video tutorial, Django view, URL routing scheme  {| border=1 |- || &amp;#039;&amp;#039;&amp;#039;Visual cue&amp;#039;&amp;#039;&amp;#039; || &amp;#039;&amp;#039;&amp;#039;Narration&amp;#039;&amp;#039;&amp;#039; |-...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;'''Title of script:'''Creating Views and Design URLs&lt;br /&gt;
&lt;br /&gt;
'''Keywords: '''Video tutorial, Django view, URL routing scheme&lt;br /&gt;
&lt;br /&gt;
{| border=1&lt;br /&gt;
|-&lt;br /&gt;
|| '''Visual cue'''&lt;br /&gt;
|| '''Narration'''&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: Creating Views and Designing URLs&lt;br /&gt;
|| Hello and welcome to the spoken tutorial on “Creating '''Views''' and Designing '''URLs'''”&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: Learning Objectives&lt;br /&gt;
|| In this tutorial, we will learn to:&lt;br /&gt;
&lt;br /&gt;
* Create a '''Django view'''&lt;br /&gt;
* Create a '''URL''' routing scheme&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: System Requirements&lt;br /&gt;
|| To record this tutorial, I am using&lt;br /&gt;
&lt;br /&gt;
* '''Ubuntu Linux 16.04 OS'''&lt;br /&gt;
* '''Python 3.5 '''&lt;br /&gt;
* '''Python 3.4-venv''' or higher&lt;br /&gt;
* '''gedit Text Editor '''and&lt;br /&gt;
* '''Firefox '''web browser&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: Prerequisites&lt;br /&gt;
|| To follow this tutorial, you need to know&lt;br /&gt;
&lt;br /&gt;
* How to create models in '''Django'''&lt;br /&gt;
* If not, then please go through the pre-requisite tutorials in this series.&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: What is a view?&lt;br /&gt;
|| &lt;br /&gt;
* A '''view''' is a code that accepts a request&lt;br /&gt;
* It processes the request and sends back a response&lt;br /&gt;
|- &lt;br /&gt;
|| Open a Terminal window&lt;br /&gt;
&lt;br /&gt;
Press CTRl+ALT+T simultaneously&lt;br /&gt;
|| Let us open the '''terminal '''by pressing '''Ctrl''', '''Alt''' and '''T '''keys simultaneously on our keyboard.&lt;br /&gt;
|- &lt;br /&gt;
|| [Terminal]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
cd '''my-django '''[Enter]&lt;br /&gt;
|| Now using '''cd''' command, go to the folder '''my hyphen django '''which we had created earlier.&lt;br /&gt;
|-&lt;br /&gt;
|| [Terminal]&lt;br /&gt;
&lt;br /&gt;
Type source myapp_env/bin/activate &lt;br /&gt;
&lt;br /&gt;
and press Enter&lt;br /&gt;
|| Let us activate the '''virtual environment myapp underscore env'''&lt;br /&gt;
&lt;br /&gt;
Type '''source &amp;lt;space&amp;gt; myapp underscore env slash bin slash activate '''&lt;br /&gt;
&lt;br /&gt;
And press '''Enter.'''&lt;br /&gt;
|-&lt;br /&gt;
|| [Terminal] &lt;br /&gt;
&lt;br /&gt;
cd mysite and Press Enter&lt;br /&gt;
|| Now let us go to the '''mysite''' folder by typing &lt;br /&gt;
&lt;br /&gt;
'''cd &amp;lt;space&amp;gt; mysite''' and press '''Enter'''.&lt;br /&gt;
|-&lt;br /&gt;
|| &lt;br /&gt;
|| Here onwards, please remember to press the '''Enter''' key after typing each '''command'''.&lt;br /&gt;
|-&lt;br /&gt;
|| [Terminal]&lt;br /&gt;
|| In previous tutorial, we have used '''Admin app '''for our '''app''' models&lt;br /&gt;
|-&lt;br /&gt;
|| [Terminal]&lt;br /&gt;
&lt;br /&gt;
Type gedit blog/views.py &amp;amp; [Enter]&lt;br /&gt;
|| To create a''' view '''for''' blog '''app,&lt;br /&gt;
&lt;br /&gt;
Type''' gedit &amp;lt;space&amp;gt; blog slash views dot py &amp;lt;space&amp;gt; ampersand'''&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''from django.shortcuts import render'''&lt;br /&gt;
&lt;br /&gt;
'''&amp;lt;nowiki&amp;gt;# Create your views here.&amp;lt;/nowiki&amp;gt;'''&lt;br /&gt;
|| We are now in '''views.py''' file&lt;br /&gt;
&lt;br /&gt;
Let us understand the written code later, because we will use '''render''' later&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py] Type:&lt;br /&gt;
&lt;br /&gt;
from django.http import HttpResponse &lt;br /&gt;
&lt;br /&gt;
def index(request): &lt;br /&gt;
&lt;br /&gt;
return HttpResponse(&amp;quot;Hello World&amp;quot;)&lt;br /&gt;
|| Now, let us create a simple view''' '''and see how it works.&lt;br /&gt;
&lt;br /&gt;
Type the code as shown here&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''def index'''(request): &lt;br /&gt;
|| Here, we have defined a function named '''Index'''&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
def index'''(request): '''&lt;br /&gt;
|| Each view function takes an '''Http Request''' object as its first parameter, &lt;br /&gt;
&lt;br /&gt;
Here I have named the parameter as '''request '''&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
from django.http import HttpResponse &lt;br /&gt;
&lt;br /&gt;
Highlight '''HttpResponse''' &lt;br /&gt;
|| '''HttpResponse''' class lives in the '''django dot http '''module&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''from django.http import HttpResponse'''&lt;br /&gt;
|| For that, we import '''HttpResponse''' from '''django dot http '''module&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
return HttpResponse'''(&amp;quot;Hello World&amp;quot;) '''&lt;br /&gt;
|| Here, the view returns the '''HttpResponse '''as '''Hello World'''&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''from django.http import HttpResponse'''&lt;br /&gt;
&lt;br /&gt;
'''def index(request): '''&lt;br /&gt;
&lt;br /&gt;
'''return HttpResponse(&amp;quot;Hello World&amp;quot;)'''&lt;br /&gt;
|| This is the simplest view, we have created in '''Django'''&lt;br /&gt;
|-&lt;br /&gt;
|| Press Ctrl+S&lt;br /&gt;
|| Save the file.&lt;br /&gt;
|-&lt;br /&gt;
|| Switch to Terminal&lt;br /&gt;
|| Switch back to the '''terminal.'''&lt;br /&gt;
|-&lt;br /&gt;
|| [Terminal]&lt;br /&gt;
&lt;br /&gt;
Type gedit blog/urls.py &amp;amp; and press Enter&lt;br /&gt;
|| To call the view, we need to map it to a URL. &lt;br /&gt;
&lt;br /&gt;
For this we need a URL configuration&lt;br /&gt;
&lt;br /&gt;
Create a file called '''urls dot py''' in '''blog''' app directory&lt;br /&gt;
&lt;br /&gt;
Type '''gedit &amp;lt;space&amp;gt; blog slash urls dot py &amp;lt;space&amp;gt; ampersand'''&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py] Type:&lt;br /&gt;
&lt;br /&gt;
from django.urls import path&lt;br /&gt;
&lt;br /&gt;
from . import views&lt;br /&gt;
&lt;br /&gt;
urlpatterns = [ &lt;br /&gt;
&lt;br /&gt;
path('index/', views.index, name='index'),&lt;br /&gt;
&lt;br /&gt;
]&lt;br /&gt;
|| We are now in '''urls.py''' file in''' blog '''app directory&lt;br /&gt;
&lt;br /&gt;
Let us add our first '''URL pattern''' as shown here&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py] &lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''urlpatterns''' = [ &lt;br /&gt;
|| The''' URL patterns''' determine which view will be called&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py] &lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''from django.urls import path'''&lt;br /&gt;
|| For that, we need to import '''path '''from '''django.urls '''modules&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py] &lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''path'''&lt;br /&gt;
|| '''Path''' '''function''' allows to route '''URLs''' to view&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py] &lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
path(''''index/', views.index, name='index''''),&lt;br /&gt;
|| The arguments of the '''path function''' are '''route, view, and namespace'''&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py] &lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
path(''''index/'''', views.index, name='index'),&lt;br /&gt;
|| The '''route''' argument should be a string that contains a '''URL pattern'''. &lt;br /&gt;
&lt;br /&gt;
Here '''index slash''' is the route argument. &lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py] &lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
path('index/ ', '''views.index,''' name='index')&lt;br /&gt;
|| The view argument is '''blog’s '''view function that to map with URL&lt;br /&gt;
&lt;br /&gt;
Here, the path routes the view function '''Index''' to the URL mentioned.&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py] &lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
path('index/', views.index, '''name='index''''),&lt;br /&gt;
|| The '''name '''argument is used to identify the '''URL'''&lt;br /&gt;
&lt;br /&gt;
It is used to perform''' URL''' reversing.&lt;br /&gt;
&lt;br /&gt;
We shall understand this in later tutorials&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py] &lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''from . import views'''&lt;br /&gt;
|| We import '''views''' from the '''blog''' app&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py] &lt;br /&gt;
|| We have now created '''blog''' app '''urls dot py'''.&lt;br /&gt;
&lt;br /&gt;
It will hold all the '''URLs''' related to our '''blog '''application&lt;br /&gt;
|-&lt;br /&gt;
|| Press Ctrl+S&lt;br /&gt;
|| Save the file.&lt;br /&gt;
|-&lt;br /&gt;
|| Switch to Terminal&lt;br /&gt;
|| Switch back to the '''terminal.'''&lt;br /&gt;
|-&lt;br /&gt;
|| [Terminal]&lt;br /&gt;
&lt;br /&gt;
Type ls mysite [Enter]&lt;br /&gt;
|| Now type '''ls &amp;lt;space&amp;gt; mysite''' &lt;br /&gt;
|-&lt;br /&gt;
|| [Terminal]&lt;br /&gt;
&lt;br /&gt;
Highlight &lt;br /&gt;
&lt;br /&gt;
'''urls.py '''&lt;br /&gt;
|| We see the project’s '''URL'''&lt;br /&gt;
&lt;br /&gt;
We need to include '''app’s''' '''URLs '''in the '''mysite’s''' '''URL''' that is the '''root URL'''&lt;br /&gt;
|-&lt;br /&gt;
|| [Terminal]&lt;br /&gt;
&lt;br /&gt;
Type gedit mysite/urls.py &amp;amp; and press Enter&lt;br /&gt;
|| Clear the '''terminal'''&lt;br /&gt;
&lt;br /&gt;
Let us open the url.py file located under mysite folder&lt;br /&gt;
&lt;br /&gt;
Type''' gedit &amp;lt;space&amp;gt; mysite slash urls dot py &amp;lt;space&amp;gt; ampersand'''&lt;br /&gt;
|-&lt;br /&gt;
|| [mysite/urls.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''from django.urls import path'''&lt;br /&gt;
|| We are in now in '''root urls.py''' file &lt;br /&gt;
&lt;br /&gt;
Note that, it already imported the '''django.urls.path '''module&lt;br /&gt;
|-&lt;br /&gt;
|| [mysite/urls.py]&lt;br /&gt;
&lt;br /&gt;
Type path('blogs/', include('blog.urls', namespace='blogs'))&lt;br /&gt;
|| We need to include our '''blog app''' '''URLs''' in the '''urlpatterns''' list&lt;br /&gt;
&lt;br /&gt;
In the '''urlpatterns''' list value, type as shown&lt;br /&gt;
|-&lt;br /&gt;
|| [mysite/urls.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
path(''''blogs/'''', include('blog.urls', namespace=’blog’)),&lt;br /&gt;
|| Here, we added app name '''blogs''' as a route argument.&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| [mysite/urls.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
path('blogs/', '''include'''('blog.urls', namespace='blog')),&lt;br /&gt;
|| Include function takes a full '''Python''' import path to another '''URL''' configuration module&lt;br /&gt;
&lt;br /&gt;
In our case it is the '''blog apps URL'''&lt;br /&gt;
|-&lt;br /&gt;
|| [mysite/urls.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
from django.urls import path''', include'''&lt;br /&gt;
|| For that we need to import '''include '''from '''django.urls''' module&lt;br /&gt;
&lt;br /&gt;
So in the line '''from django.urls import path '''add&lt;br /&gt;
&lt;br /&gt;
'''comma space include'''&lt;br /&gt;
|-&lt;br /&gt;
|| [mysite/urls.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
path('blogs/', include('blog.urls', '''namespace='blog'''')),&lt;br /&gt;
|| Naming '''URL patterns''' is not to clash with other applications’ names&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Press Ctrl + S&lt;br /&gt;
|| Save the file and switch to the '''blog’s''' '''App''' '''urls.py''' file.&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py]&lt;br /&gt;
&lt;br /&gt;
Type app_name = 'blog' &lt;br /&gt;
|| We need to include '''app''' '''underscore''' '''name''' as '''blog''' before the beginning of '''URL pattern'''&lt;br /&gt;
&lt;br /&gt;
Type the code as shown here.&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''app_name = 'blog' '''&lt;br /&gt;
|| '''Django '''uses''' '''it to look for the matching application namespace in the '''URL''' file in '''Root '''directory&lt;br /&gt;
|-&lt;br /&gt;
|| Switch back to Terminal&lt;br /&gt;
|| We have now included view from '''blog''' application &lt;br /&gt;
&lt;br /&gt;
Save the file and switch back to '''Terminal'''&lt;br /&gt;
|-&lt;br /&gt;
|| [Terminal]&lt;br /&gt;
&lt;br /&gt;
Run the server&lt;br /&gt;
&lt;br /&gt;
Type python manage.py runserver and press Enter&lt;br /&gt;
|| Let's run the '''Django''' '''development server.'''&lt;br /&gt;
&lt;br /&gt;
Type''' python &amp;lt;space&amp;gt; manage dot py &amp;lt;space&amp;gt; runserver '''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Open a browser and type &lt;br /&gt;
&lt;br /&gt;
localhost:8000/blogs/index&lt;br /&gt;
|| Now, open a web browser and type &lt;br /&gt;
&lt;br /&gt;
localhost:8000/blogs/index&lt;br /&gt;
|-&lt;br /&gt;
|| [Browser]&lt;br /&gt;
&lt;br /&gt;
'''Output:'''&lt;br /&gt;
&lt;br /&gt;
'''“Hello World'''”&lt;br /&gt;
|| Here, we can see the text '''&amp;quot;Hello World&amp;quot;''', which is defined in the index view&lt;br /&gt;
|-&lt;br /&gt;
|| Switch back to editor blog/views.py&lt;br /&gt;
|| Let us add few more lines to display our blog object that we created in the previous tutorial.&lt;br /&gt;
&lt;br /&gt;
Now, Switch back to '''views dot py''' file in the text editor.&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]Type:&lt;br /&gt;
&lt;br /&gt;
def get_blogs(request): blogs = Blog.objects.all() &lt;br /&gt;
&lt;br /&gt;
return HttpResponse(blogs)&lt;br /&gt;
|| Now below the index function, Let us define a new function '''get underscore blogs'''&lt;br /&gt;
&lt;br /&gt;
Type the code as shown here&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Type &lt;br /&gt;
&lt;br /&gt;
from .models import Blog &lt;br /&gt;
|| To get the '''Blog '''objects, we need to import '''Blog''' from models&lt;br /&gt;
&lt;br /&gt;
So next to the line importing '''HttpResponse''', type the code as shown here&lt;br /&gt;
&lt;br /&gt;
'''from dot models import Blog '''&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''def get_blogs(request):'''&lt;br /&gt;
|| The function '''get underscore blogs''' will gives the '''blog '''object&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''blogs = Blog.objects.all()'''&lt;br /&gt;
|| This is an query, which gets all objects in '''Blog''' model&lt;br /&gt;
&lt;br /&gt;
We will learn about this in detail in the upcoming tutorials&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
return HttpResponse('''blogs''')&lt;br /&gt;
|| Then, The view returns the '''blog''' object&lt;br /&gt;
|-&lt;br /&gt;
|| Press Ctrl + S&lt;br /&gt;
|| Save the file&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Switch to blog/urls.py editor from blog/views.py &lt;br /&gt;
|| Next step to configure our view with URL&lt;br /&gt;
&lt;br /&gt;
For that, switch to the '''blog app’s url.py''' file in the text editor&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py]&lt;br /&gt;
&lt;br /&gt;
path('get_blogs/',views.get_blogs, name='get_blogs'), &lt;br /&gt;
|| We are now in '''urls.py''' file in '''blog app'''&lt;br /&gt;
&lt;br /&gt;
Insert the '''path''' for '''get underscore blogs''' in the '''URL pattern list'''&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
path('get_blogs/','''views.get_blogs''', name=’get_blogs')&lt;br /&gt;
|| '''Views dot get underscore blogs function''' is assigned''' '''to the URL '''get_blogs'''&lt;br /&gt;
|-&lt;br /&gt;
|| [blog/urls.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''name='get_blogs''''&lt;br /&gt;
|| The last part '''name equals to get underscore blogs''' is the name of URL used to identify the view&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Press Ctrl+S&lt;br /&gt;
|| We have modified our code to display our '''blog '''objects&lt;br /&gt;
&lt;br /&gt;
Save the file.&lt;br /&gt;
|-&lt;br /&gt;
|| Switch to Browser&lt;br /&gt;
|| Switch back to the Browser'''.'''&lt;br /&gt;
|-&lt;br /&gt;
|| Open a browser and type localhost:8000/blogs/get_blogs&lt;br /&gt;
|| To call the view function '''get underscore blogs'''&lt;br /&gt;
&lt;br /&gt;
On the browser, type localhost:8000/blogs/get_blogs&lt;br /&gt;
&lt;br /&gt;
And Press '''Enter'''&lt;br /&gt;
|-&lt;br /&gt;
|| [Browser]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''Blog object(1)'''&lt;br /&gt;
|| Here, we can see the '''Blog '''object that was created in previous tutorial&lt;br /&gt;
|-&lt;br /&gt;
|| Switch back to Slide&lt;br /&gt;
|| Now we have created a simple client-server model&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: Client Server model&lt;br /&gt;
|| &lt;br /&gt;
* All web systems follows the Client Server model&lt;br /&gt;
* A server responds to all the requests sent by client&lt;br /&gt;
* Information contained in this request are stored in the database on the server side&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Switch back to editor&lt;br /&gt;
|| Let us switch back to '''views dot py''' file in the text editor&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
response = 'Blogs:'for blog in blogs: response += '&amp;lt;br \&amp;gt; {0}'.format(blog) return HttpResponse(response)&lt;br /&gt;
|| We are now in '''views dot py''' file&lt;br /&gt;
&lt;br /&gt;
Let us modify our view to display an individual blog &lt;br /&gt;
&lt;br /&gt;
Modify the function get_blogs as shown&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''response = 'Blogs:''''&lt;br /&gt;
|| This is the response, that is relevant to the user&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''for blog in blogs: '''&lt;br /&gt;
|| This for loop fetches each individual blog from the blogs list&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''response += '&amp;lt;br \&amp;gt;{0}'.format(blog)'''&lt;br /&gt;
|| Then performs a string formatting operation&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
''''{0}'.format(blog)'''&lt;br /&gt;
|| In String Format method, we pass blog as argument in bracket&lt;br /&gt;
&lt;br /&gt;
This argument is formatted into a string in the placeholder defined by a pair of curly braces&lt;br /&gt;
&lt;br /&gt;
Here, we pass '''blog '''as value to the placeholder&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''+='''&lt;br /&gt;
|| '''Plus equal to''' performs string concatenate operation&lt;br /&gt;
&lt;br /&gt;
Here, '''blog '''values are assigned to '''response'''&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
return HttpResponse('''response''')&lt;br /&gt;
|| The return statement will return all '''Blog''' objects in '''blog''' as a '''response'''&lt;br /&gt;
|-&lt;br /&gt;
|| Press Ctrl + S&lt;br /&gt;
|| We have altered our views to get an individual blog&lt;br /&gt;
&lt;br /&gt;
Save the file.&lt;br /&gt;
|-&lt;br /&gt;
|| Switch to Browser&lt;br /&gt;
|| Now, Switch to the browser.&lt;br /&gt;
|-&lt;br /&gt;
|| [browser]&lt;br /&gt;
&lt;br /&gt;
Press '''ctrl+r '''&lt;br /&gt;
|| The modified server reloads when the views are modified and saved&lt;br /&gt;
&lt;br /&gt;
So, Reload the web page to update the changes.&lt;br /&gt;
|-&lt;br /&gt;
|| [browser]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''Blogs: Blog object(1)'''&lt;br /&gt;
|| Now, it is only displaying the '''blog objects '''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| &lt;br /&gt;
|| Let us switch to '''views dot py''' file in the text editor &lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
articles = Article.objects.filter(blog=blog)response += ','.join([article.title for article in articles])&lt;br /&gt;
|| Now let us add a code to display '''articles''' related to a '''blog '''in the view&lt;br /&gt;
&lt;br /&gt;
Before the get underscore blogs return statement, type the code as shown here&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''articles = Article.objects.filter(blog=blog)'''&lt;br /&gt;
|| This query will filter the '''Article''' objects related to '''Blog''' model &lt;br /&gt;
&lt;br /&gt;
Query has the general form of “'''object = Model.objects.get(id=id)'''”&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''response += ','.join([article.title for article in articles])'''&lt;br /&gt;
|| The next statement will concatenate the '''Article '''object in respect to the''' Blog '''object&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
from .models import Blog''', Article'''&lt;br /&gt;
|| To do this, we have to import '''Article''' from our Models&lt;br /&gt;
&lt;br /&gt;
So in the line '''from dot models import Blog''' add&lt;br /&gt;
&lt;br /&gt;
'''comma Article'''&lt;br /&gt;
|-&lt;br /&gt;
|| [views.py]&lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
return HttpResponse('''response''')&lt;br /&gt;
|| Now this return function will return both '''Blogs '''and '''Articles '''related to the '''blog '''model&lt;br /&gt;
|-&lt;br /&gt;
|| Press Ctrl + S&lt;br /&gt;
|| We have now edited the view to display '''Articles '''related to a '''Blog'''&lt;br /&gt;
&lt;br /&gt;
Save the file&lt;br /&gt;
|-&lt;br /&gt;
|| Switch back to browser&lt;br /&gt;
|| Switch back to the browser&lt;br /&gt;
|-&lt;br /&gt;
|| [browser] Press ctrl+r &lt;br /&gt;
&lt;br /&gt;
Highlight&lt;br /&gt;
&lt;br /&gt;
'''Blogs: Blog object(1) My Article'''&lt;br /&gt;
|| Refresh the page.&lt;br /&gt;
&lt;br /&gt;
Now we can see the '''My Article''' object which we have created in the previous tutorial&lt;br /&gt;
|-&lt;br /&gt;
|| [Terminal]&lt;br /&gt;
&lt;br /&gt;
Press Ctrl+C keys&lt;br /&gt;
&lt;br /&gt;
|| Let us now stop the '''server '''and deactivate the '''virtual environment.'''&lt;br /&gt;
&lt;br /&gt;
Switch to the '''terminal''' and press '''Ctrl''' and '''C''' keys to stop the '''server'''. &lt;br /&gt;
|-&lt;br /&gt;
|| [Terminal]&lt;br /&gt;
&lt;br /&gt;
Type deactivate [Enter]&lt;br /&gt;
|| Then type '''deactivate''' and press '''Enter'''.&lt;br /&gt;
|-&lt;br /&gt;
|| &lt;br /&gt;
|| With this, we come to the end of this tutorial&lt;br /&gt;
&lt;br /&gt;
Let us summarize.&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: Summary&lt;br /&gt;
|| In this tutorial, we have learnt about&lt;br /&gt;
* Create a '''Django''' view&lt;br /&gt;
* Create a '''URL''' routing scheme&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: Assignment&lt;br /&gt;
|| As an assignment,&lt;br /&gt;
* Create a''' view count_blogs '''for''' '''displaying the number of''' blogs.'''&lt;br /&gt;
&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: About Spoken Tutorial project&lt;br /&gt;
|| The video at the following link summarises the Spoken Tutorial project.&lt;br /&gt;
&lt;br /&gt;
Please download and watch it.&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: Spoken Tutorial workshops&lt;br /&gt;
|| The '''Spoken Tutorial Project''' team conducts workshops and gives certificates.&lt;br /&gt;
&lt;br /&gt;
For more details, please write to us.&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: Forum for specific questions:&lt;br /&gt;
|| Please post your timed queries in this Forum.&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: FOSSEE to answer questions&lt;br /&gt;
|| Please post your general or technical questions in this Forum.&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: Acknowledgement&lt;br /&gt;
|| Spoken Tutorial Project is funded by NMEICT, MHRD, Government of India.&lt;br /&gt;
&lt;br /&gt;
More information on this mission is available at this link.&lt;br /&gt;
|-&lt;br /&gt;
|| Slide: Thanks Slide&lt;br /&gt;
|| This script has been contributed by Thiagarajar College of Engineering and the FOSSEE Project, IIT Bombay.&lt;br /&gt;
&lt;br /&gt;
The video has been recorded by Praveen from Spoken Tutorial Project, IIT Bombay.&lt;br /&gt;
&lt;br /&gt;
Thanks for watching.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Pravin1389</name></author>	</entry>

	</feed>