0
0
Djangoframework~30 mins

Returning HTML templates in Django - Mini Project: Build & Apply

Choose your learning style9 modes available
Returning HTML templates in Django
📖 Scenario: You are building a simple website for a local bookstore. You want to show a welcome page to visitors.
🎯 Goal: Create a Django view that returns an HTML template called welcome.html to display the welcome page.
📋 What You'll Learn
Create a Django view function named welcome_view
Use the render function to return the welcome.html template
Add a URL pattern that maps the root URL '' to welcome_view
Create a basic welcome.html template with a heading
💡 Why This Matters
🌍 Real World
Websites often need to show pages with HTML content. Django helps by letting you write views that return HTML templates easily.
💼 Career
Knowing how to return HTML templates in Django is essential for backend web developers working with Python and Django frameworks.
Progress0 / 4 steps
1
Create the welcome.html template
Create a file named welcome.html inside the templates folder. Add an <h1> tag with the text Welcome to the Bookstore.
Django
Need a hint?

Use an <h1> tag inside the HTML file with the exact text.

2
Create the Django view function welcome_view
In your Django app's views.py, create a function named welcome_view that takes request as a parameter.
Django
Need a hint?

Define a function with the exact name welcome_view and one parameter request.

3
Use render to return the welcome.html template
Import render from django.shortcuts. Inside welcome_view, return render(request, 'welcome.html').
Django
Need a hint?

Use return render(request, 'welcome.html') inside the view function.

4
Add URL pattern for the root URL
In your app's urls.py, import welcome_view and add a URL pattern that maps the empty string '' to welcome_view.
Django
Need a hint?

Use path('', welcome_view, name='welcome') inside urlpatterns.