In this video we are creating a template and using it in django. Also sending the value to html page.
Using HTML Page
1. create django project
2. create directory for HTML pages in your Django Project
e.g. template
3. create HTML file in directory templates
e.g. home.html (with some tages Hello World )
4. in views.py file type
def home(request):
return render(request, 'home.html')
5. in settings.py file in your project add following code
TEMPLATES = [
'DIRS': [os.path.join(BASE_DIR,'template')],
]
6. Run application
python manage.py runserver
click on link 127.0.0.1:8000
To add variable in HTML
1. in views.py file type
def home(request):
return render(request, 'home.html',{'myvar':'Yogesh'})
2. to use that variable in HTML write following code in html tag
Hello {{myvar}}
3. Run application
python manage.py runserver
click on link 127.0.0.1:8000