Repository navigation
Django Templates
Travis Ditmanson edited this page Sep 10, 2023
·
1 revision
Active python virtual environment Django application set up complete
You'll need an http request for an html document
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
# Render index.html
return render( request, 'portfolio_app/index.html')For this application create the following file path to store templates
app/templates/app
create a base html template for reuse.
create an index.html template to call from
- index.html is the naming convention for a web applications homepage. Insert the base template into your index
<!-- inherit from base.html -->
{% extends 'portfolio_app/base_template.html' %}
<!-- Replace block content in base_template.html -->
{% block content %}
<h1>Computer Science Portfolios</h1>
<h2>More to come</h2>
{% endblock %}Static files such as css/images/documents should be sourced from a static folder.
- At the same layer as your project, application, and virtual environment, add a directory called satic.
- Create sub directories for file types.
- To use import static objects at the top of the page
-
{%load static%}An example of how to import a static item into a html tag: <img src="{% static 'images/uccs_logo.gif' %}">