#5 Django tutorials | Django Template Language | DTL
ฝัง
- เผยแพร่เมื่อ 11 ก.ย. 2024
- In this lecture we are discussing about:
#1 DTL (Django Template Language)
a) use of DTL in Django
b) use dynamic content in Django
#2 use of Jinja template example in Django.
-- in views.py you can use html tag inside HttpResponse
def home(request):
-- it work fine to use tag inside HttpResponse
-- but if you want a big page then you need to create a template
-- and this has a dynamic page
#1 DTL (Django Template Language)
we have concept of DTL (Django Template Language)
-- other option in django is jinja template
--generally you created the app outside the app
-- and then you can use it in your project
-- you can create a folder with name templates outside the app folder
Now in templates folder you can create a html file
-- home.html
Now you go to telusko folder inside change the settings.py
-- in templates
-- in DIRS change the path [os.path.join(BASE_DIR,'templates')],
-- now you can use the template in your views.py
a) Now you need to change the views.py
-- from django.shortcuts import render
-- from django.http import HttpResponse
-- def home(request):
-- return render(request,'home.html')
b) now you get dynamic content
-- now you want to pass some dynamic value from views.py
inside this home function add JSON data
-- def home(request):
-- return render(request,'home.html'{'name','Navin'})
-- go to templates and next to home.html
-- changing content in json file will change the content in html file
#2 use of Jinja template example in Django.
-- this curly braces {{name}} simply means jinja templates or pattern
-- we can do operation in jinja templates
-- you can use jinja templates instead of DTL
-- but DTL is by default in django
Python Tutorials for beginner : bit.ly/2qfhUCp
Django Tutorials : • #1 Django tutorials | ...
Django is a high-level Python-based free and open-source web framework, which follows the model-view-template (MVT) architectural pattern.
It is maintained by the Django Software Foundation (DSF).
Django's primary goal is to ease the creation of complex, database-driven websites.
Some well-known sites that use Django include the Public Broadcasting Service, Instagram, Mozilla, The Washington Times, Disqus, Bitbucket, and Nextdoor.
In this video we will see:
Django Tempalte Language
Including HTML tags in a program
Create Django Template to create dynamic webpage
Editing settings.py file
Github :- github.com/nav...
Editing Machines & Monitors :
amzn.to/2HA6ra8
amzn.to/2VMBBPw
amzn.to/2RfKWgL
amzn.to/2Q665JW
amzn.to/2OUP21a.
Check out our website: www.telusko.com
courses.telusko.com
Instagram : / navinreddy20
Twitter : / navinreddy20
Facebook:
Telusko : / teluskolearn. .
Navin Reddy : / navintelusko
Subscribe to our other channel:
Navin Reddy : / @navinreddy
Telusko Hindi : / @teluskohindi
Donation & Support:
Indian Payment : www.instamojo....
PayPal Id : navinreddy20
Patreon : navinreddy20
If anybody gets an error -> "os is not defined"
Then, in the settings file type "import os" right after the path import line
That will fix your error.
Well thanks alot man
Bro it is still not working any idea?? It is showing os.path.join is unsubscriptable
Thanks❤️
Thanks brother
thank you, you are a good man
This guy is good. The way he explains everything leaves you smiling. Thank you Telusko
I wish this video was available when I was learning Django.
I had to go through so much self-learning for just small and simple stuff like this.
nicely explained.
@vishal Can you please tell me your progress now, like you still in django?
@@OasisFinder no I ending as MERN stack and spring boot developer.
Django got discontinued😅
@@Mr-Multiplayer Hahahah... Bro i am learning and hoping to get a job as a web developer , Can i ask why you stop using django?
@@OasisFinder when I was learning there was very less content out there on django.
Many didn't know. I had a person guiding me in spring boot so I switched.
@@OasisFinder its really good complete it. All the best.
Man, you are a gem. Lots of love from Bangladesh.
I watched several tutorials on django and always got confused.
This is more clear and precise. Thank you....
Good sir.... I like ur way of teaching, you r only my way through whom I learnt python....Thanx a lot sir.....
Sir please make a project after the competition of Django series...
saw other videos on django and stopped leaning it but the way u teach makes it interesting and makes me want to learn
hey please tell me why template doesn't exist error is facing me and
How to use os.path.join os is not defined
Bro iam also getting that, would you help me resolve that error😢
Thanks a lot Navin Sir. This tutorial is really amazing. I have watched basic python tutorial and that was really awesome. After watching this series anyone can do programming in python.
Once again thank you very much sir.
I keep getting template error
What do i do ?
Thanks a lot sir, for taking the effort and making amazing video's for us! A big thank you from the bottom of my heart!
why from the bottom of the heart?
ERROR "OS IS NOT DEFINED"
If you've started a new Django 3.1+ project and are using older tutorials or guides, it's likely to come across the following error on your command line:
NameError: name 'os' is not defined
Starting with Django 3.1, the startproject command generates a settings.py file that imports pathlib rather than os on the top line.
The quick fix is to import os at the top of your settings.py file:
# settings.py
import os # new
from pathlib import Path
The better fix is learn more about how pathlib works and update your BASE_DIR, DATABASES, STATICFILES_DIRS, and other files to use the newer, modern approach.
OR
In settings.py file on the top you will see
from pathlib import Path
add (import os) command above it
like this
import os
from pathlib import Path
whoever is facing template error can add the path 'telusko/templates' in 'DIRS': [os.path.join(BASE_DIR,'telusko/templates')], you can easily see the path used for home.html in homepage with this label name 'django.template.loaders.filesystem.Loader' under 'Template-loader postmortem'
yes....syntax should be like this DIRS': [os.path.join(BASE_DIR , 'app_name/templates')],
app_name should be the same app_name under which templates were created.
thank you , it works
@Anamika Kumari....problem solved......thanks!🙏
Thank you it really solved my problem i was so worried and irritated...thanks alot
@@noeldeepakpalle442thank you so much it really resolved my error .....❤
These are some Really productive sessions with a good pace 🔥
raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: home.html
i am getting the above error . please someone help me out. im cracking my head out to resolve that but it isnt executing . navin sir please help me out
bro i got same error
@@neelakantareddy5794 yeah bro just give "templates" in the settings page dont mention telusko/templates or your app_name/templates
this is great. i had to check my speed to see if i left it on 1.5x. hahahahah. :)
Exception Value:
home.html
It showing NameError: name 'os' is not defined
You are a great teacher. I studied different programming languages from you. Thank you, sir.
thank you sir we always get awesome learning from your videos.
its your efforts , once again thanks a lot
The way you r teaching is very good and easy to understand..... I hope u will keep videos on machine learning...
Thanks Sir , You are really an awesome educator and by providing all these free courses you are doing great !!!!!!!
Really thank you sir, you are all efforts for us.. its very clear understanding explanation. also helping us to practice.
These tutorials, the way he present lectures is fucking amazing!!!
What a man sir you are ? 🔥Full of positive vibes, I know that Django is not easy to learn. But you are making it easy for us. Thanks Guru🙏🏻
Absolutely candid presentation. Very nice Mr. Navin.
I am following the series, its really useful. Loving it so far.
thanks navin sir for the tutorial. really helpful . your tutorials are one of the best in respective categories.
Hey!!! Navin, Yes, I am enjoying your videos... Thank You...
thanks a lot for sharing so useful videos ... after watching them actually one can understand whats going on in Django and what to do further
Hey, I am having some issues while we are using render and request. I tried undoing everything i was working till the last video but every time i run this one, it says that template does not exist ! I tried finding answers on internet and but the solutions they had given were simply not working for me. Can you help me out and tell me the reason behind this @Telusko
facing same issue
yah I also
it might be because of the templates folder location. If you have mentioned BASE_DIR then your templates folder should be out of your project folder, but as you are receiving this error means you have created the templates folder inside your project folder.
@@shubhamswami3507 man thats exactly what was the issue! Thank you so much!
@@shubhamswami3507 Thank you so much
u are a great teacher sir ....love from #Pakistan
Really thank you so much sir ,nearly i tried to make a project using django but every day im getting err but after so many tries i got output.Thank you so much sir.keep explain more nd more
Can you help me i am also getting error
I have some difficulty with English because I'm Brazilian, but even so I managed to understand enough to be able to say "you helped me and conquered my like"
i watch annoying ads without skip in exchange for ur service sir.
Ek damm jhkaaas
Amazing but simple explanation of django dynamic temple
If you are getting TemplateNotFoundError then try removing the path, adding it and saving it in the Settings Also, refresh the server. It worked for me. Happy Learning :)
didnt work for me, what should i do>?
i followed your steps and it didn't work and keeps telling me "templates doesn't exist" !!!
same
same problem
make sure that the template is in the same folder where calc is.
@@prasunshiwakoti2225 thanks brother.
@@prasunshiwakoti2225 lifesaver
Amazing teaching skill sir. Love your teaching.
I Feel relex after listening telusko starting music and welcome aliens, and too with mycodeschool creator voice. 😊😊
Excellent videos sir, we are enjoying very much. Thanks a lot for creating this awesome stuff for us.
Thanks Navin you are doing amazing work.
I like ur video before watching!!! I am damn sure it will be good
you are simply amazing sir!
Good video
wonderful video sir !! simple and smooth 👌
Tq sir for starting Django series 👌👌👌
Plz complete all videos as soon as possible 🙏
And plz do video on http methods
Thank you very much 😊❤️ for clearing my doubt
Templatedoesnot exist error
sir i find error in that and the error is template not found
Go to your project you will find one folder inside it (whoes name will be same as of your project name) now inside that folder you will find your template folder , cut this template folder from here and paste it inside your project folder
@@davindersinghwahla thankyou sir it was helpful
Save that html file in htlml format not .py
@@davindersinghwahla i have no template folder inside that folder which u are talking about..what is the solution for this now
@@ashwaryatak2117 then try to find that template folder using search bar and after that follow same steps
in the settings,i got an error (os.path.....)when i type os,a error pops up
In settings
import os
@@vish409 thanku so much bro
@@vish409 thank you bro but now i am getting secret key error😢
@@vish409 thanks a lot
than you for making these videos i like the way you explain things
how to solve template does not exist error
Sir HTML is mandatory? For learn Django
Navin i am getting ImportError at server on the step 6:28
If anybody gets an error -> "os is not defined"
Then, in the settings file type """"import os"""""" right after the path import line
That will fix your error ! :)
NB: Do not include the quotation symbols while typing the import os function line
@@prg7dro not working bro
@@ar7242 what is the error ?
@@prg7dro got the solution bro and the error was that os one
@@ar7242 how did you fix it ?
Good explanation Thanks
Thank you Navin... Waiting for next
2:50 we want to make it dynamic -> templates background is fixed, but data is changed.
5:00 Django should know where you have all the templates
-> settings.py에서 templates DIRS 바꾸는 작업
-> 'DIRS': [os.path.join(BASE_DIR, 'templates')],
Thank you
for those getting temlpate not found error you have to save the home.html and settings file .
Sir when I was writing in settings.py's template then error coming is os is not defined....do I need to import os
same here
Hello sir
I'm getting pylint important error ,how do i solve this .
Btw your teaching is awesome
why we are returning html page since django is backend framework it is used to create api
Sir I m getting TemplateDoesnotExist error continuously
Create templates in your app and check the path of html is correct or not
Careful with spelling
In the dirs type [r'the path of file by going in the folder and using properties'] it will definetely work as it worked in my case
Maybe I'm late, but I've had this same error.
Problem was that I created the templates folder in the telusko subdirectory.
The templates folder should be on the same level as calc and telusko.
If you get an error at the home page saying TemplateDoesNotExist at/ then go to the settings.py file and at INSTALLED_APPS=[......, 'your_app_name',] (You just need to add the name of the app in the INSTALLED_APPS field)
did it but didn't work
i'm getting an exception..template doesnot exist...what can i do know
The 'template' folder may have been created under the calc or telusko folder, you have to create it under the main folder and then home.html file in it
thanks a lot for this series sir
Hello sir, I am a beginner in this Django learning and I could not get result like you got Hello World!!!! and in my case its saying that my template does not exist
same problem
if u got solution please suggest
@@ujwaladivate7444 import os after :-from pathlib import Path
doest forget to save (ctrl +s)
i hope it works !
Thank you sir... For amazing series
Well explained sir. But i m getting error as TemplateDoesNotExist. How to resolve pls suggest
Me too
Have solved yours
If yes ,
How did you do it
Awesome tutorials, thank u
your teaching is nice but who is kiran?
Great job 👏👏
in urls iam getting no module named calc how to do with it
I got everything right thanks sir.
Liked you teaching technic
Sir, I did the same as you did but,when I run the server the page is blank with white screen,can you please help me out,.
plz save the content by pressing (ctrl s)
very nice
I am in Love with you🥰
My Respect for you from the core of my soul😊🥳
Thanks a lot dear sir..Sir please make a project of Django series.
it's showing template doesn't exist at home.html
I really liked it . thank you
Super sir!!!!
Navin in installed app we have to add 'calc' otherwise helloworld not appears.....can you make some attention and add between some video about' ' import os error ' and 'templates does not exit error'
Great
,I'm getting the results but at CMD , i'm getting this ERROR -
An established connection was aborted by the software in your host machine
EDIT* - I tried different browser and it solved my problem . i know its not the best sollution but atleast it works 👍
Sir could not understand that name what u have done with that, what I meant is if I want the name of myself I can edit htlm code in home. Html, why u have created a dictionary???
Thank you so much for video!!
Why the path u set as os. path????
Cool txs
Error - name 'os' is not defined ?
Add "ᶦᵐᵖᵒʳᵗ ᵒˢ" at the very first line(1) of settings .py file
That's it, write it w/o quotation mark & save it.
why didnt get output when give bold tag instead of heading tag?
Nice intro music
Sir in this I didn't get the html page content to the web browser what is the problem
hi there you are superrr
'function' object has no attribute 'META' sir this error is coming when going through the way illustrated above by u
Sir i am facing a problem which is telling that the name 'os' is not defined