Getting the index view to render

Now, we have the index view ready. But, before this view can be served to the user, we need to provide Flask with a mapping about the endpoint on which this view will be rendered. To achieve this, let's fire up our code editor and open bugzot/__init__.py and add the following lines to the file:

from bugzot.views import IndexView
app.add_url_rule('/', view_func=IndexView.as_view('index_view'))

Here, our focus is on the second line, which is responsible for mapping our view with a URL endpoint. The add_url_rule() of our flask application is the one that is responsible for providing these mappings. The method takes as its first parameter the URL path on which the view should be rendered. The view_func parameter provided to the method takes in the view that needs to be rendered on the provided URL endpoint.

Once this is done, we are now ready to serve our index page. All we need to do now is to run the following command:

python run.py

Then visit http://localhost:8000/ on your browser.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.34.62