View functions
A view function, or “view” for short, is simply a Python function that takes a web request and returns a web response. This response can be the HTML contents of a Web page, or a redirect, or a 404 error, or an XML document, or an image, etc.
Example: You use view to create web pages, note that you need to associate a view to a URL to see it as a web page.
1.-We created a return function in HTML called hello world
In Django, the index is the main page of an app.The only HTML we request right now is the "Hello World"
URL Mapping
So basically we are mapping #index to products page ( in other words, we are making it the main page)
2.-We will close the view folder Let's create a new python file
Now we are mapping first to the root ( /products '') and 2nd to the views module
3.-Now let's collapse the product folder and open the pypyshop folder...from there go to the root in urls.py
Now we will tell django about the url mapping and the view page ( django doesn't know yet)
Finally, we will let them know about the product page
we will expand "import"..and we will add the word " , include"
In the produce tab we can see this
we are telling Django that everything with /products , send them to produce tab page
Now testing the app with the name /products
But when you come back you will see this:
Exercise:
Make a new page called new products
Make a new page called new products
Then we go back to URL to map the new Products function
Now we will check this in our browser
View functions
Reviewed by ohhhvictor
on
May 31, 2019
Rating:
Reviewed by ohhhvictor
on
May 31, 2019
Rating:
















No comments: