1. Use of Django self-study classroom template

1. Use of Django self-study classroom template

1.django manage.py startproject project_name -->Create project

2.python manage.py startapp app_name -->Create app

3.python manage.py flush -->Empty the database

4. Add the newly created app ('learn') to the settings

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'learn',
]

Use of templates

1. Basic string

views

def home(request):
    string ='Pass a string name in the view function is string to the template home.html'
    return render(request,'home.html',{'string':string})

How to display strings in home.html

 <p>{{ string }}</p>

2.for loop

views pass a list to home.html

def home(request):
    aaa = ['html','css','python']
    return render(request,'home.html',{'aaa':aaa})

How to use home.html

List of tutorials
    {% for i in aaa %}
    {{ i }}
    {% endfor %}

Tutorial list html css python

3. Display the contents of the dictionary

def home(request):
    aaa = {'name':'derek','gender':'M'}
    return render(request,'home.html',{'aaa':aaa})
Name: {{ aaa.name }}
Gender: {{ aaa.gender }}

Name: derek Gender: M

You can also loop the dictionary

{%for key,value in aaa.items%}
        {{ key }}:{{ value }}
 {% endfor %}

name:derek gender:M

Reference: https://cloud.tencent.com/developer/article/1091554 1. Use of Django self-study classroom template-Cloud + Community-Tencent Cloud