Views & Urls In Django| Python Django Tutorials In Hindi #5
ฝัง
- เผยแพร่เมื่อ 25 พ.ย. 2024
- ►Source Code + Resources - www.codewithhar...
►Full Django Playlist - • Python Django Tutorial...
►Click here to subscribe - / @codewithharry
Best Hindi Videos For Learning Programming:
►Learn Python In One Video - • Learn Python In Hindi ...
►Learn JavaScript in One Video - • JavaScript Tutorial
►Learn PHP In One Video - • Learn Php In One Video...
►Machine Learning Using Python - • Machine Learning Tutor...
►Creating & Hosting A Website (Tech Blog) Using Python - • [Hindi] Web Developmen...
►Advanced Python Tutorials - • Intermediate/Advanced ...
►Object Oriented Programming In Python - • Object Oriented Progra...
►Python Data Science and Big Data Tutorials - • Python Data Science an...
Follow Me On Social Media
►Website (created using Flask) - www.codewithha...
►Facebook - / codewithharry
►Instagram - / codewithharry
►Personal Facebook A/c - / geekyharis
Twitter - / haris_is_here
If you really want me to make a social networking website in Django in one video, share this Django series everywhere!
I will definitely make a video explaining social networking website development in one video if I get 500+ shares on my playlist!
Thanks a lot in advance to all those who shared!
Link is here - th-cam.com/play/PLu0W_9lII9ah7DDtYtflgwMwpT3xmjXY9.html
I will love to see how to make social netwoking web side
after writing python manage.py runserver
at last syntax error is showing
sir jab mera ko command 'python manage.py runserver' run karunga tab , Exception in thread django-main-thread: aah raha hei kya karu server start nahi hoo raha
How u can add apps in settings.py file of main project????
@@memoriesmaker9886 you might have forgotten to put a , after path
Tried Udemy, Lynda and everything and was facing difficulty in even understanding simple things. By luck i came here and I am stuck here. So amazing quality content. You ARE UNDERRATED
same here..truly amazing..
I totally agree with you, I even bought a course on udemy
that is .... that didn't teach you much, I hated that course
I still do
yea
actually udemy is useless i learned a lotof things here..he need a aplause
Def funtext(request):
file = open('pathofthetext', 'r')
Content = file.read()
file.close()
return httpresponse(content, content_type = 'text/plain')
def hota hai
def index(request):
file = open("1.txt",'r+')
return HttpResponse(file.read()),
This is a piece of code for the assignment task.
bro r+ matlb?
@@filmystaanchannel4501 read and write both
@@TariqAhmed_ thnx bro
@@TariqAhmed_ par mene jab r+ nhi likha tab bhi chal rha hai code.
@@filmystaanchannel4501 han by default r hota hai.
def index(request):
with open('textutils/file.txt', 'r') as rm:
return HttpResponse(rm.read())
PycharmProjects\textutils>cd textutils
than you enter to textutils....... thanks haarry bro
love you
from django.http import HttpResponse
def index(request):
with open("filepath/one.txt") as f:
a = f.read()
return HttpResponse(a)
Import error is coming
in my case no error is showing ....but still not displaying content in the server.
@@salmanali-bf4nk first of all always specify filemode ----> with open("path_to_file",'r') as f: ------- and keep rest of the code same :) and make sure your file shares the same directory as that of manage.py
I do your quiz by creating a text file and make a function name test in views file and then use file handling and do like
def test(request):
f1 = open("first.txt", "r")
return HttpResponse(" %s " % (f1.read()))
Thanks sir!🙏
By the way sir, can u plz explain what is the purpose of % sign here? Hope u'll help me. Thanks once again.
@@hardcode5394 docs.python.org/2/library/stdtypes.html#string-formatting-operations
It is a way of string formatting.. OPen the abouve link and you'll definitely understand from example..
Respected Mr. @@madhavaneja6573, thanks a lot for ur help.🙏
Yar mera ek masla h solve kro ge to bari meherbani hogi aap ki 😄
Sb kuch sahi h lekin file1.txt not found error araha ha wo txt file bhi wahin pr ha jahan views.py and urls.py ha
def index(request):
with open("1.txt", "r") as f: # Opening the file in read mode, we don't use r+ because file already exists, r+ is used when file doesn't exists then assigning it a variable named f
content = f.read() # Reading the contents of the file and storing it in a variable, we use read instead of readlines because readlines gives each line as a list element
return HttpResponse(content)
This code where exactly we have to write ?
do we need to make file as 1.txt ?
@@ektapatil5574 yep, "r" mode reads an already existing file. So have "1.txt" in the directory with some content in it.
9:45
def index(request):
with open('../1.txt') as file:
data = file.read()
return HttpResponse(data)
can you explain me what is he trying to ask exactly?
def goal(request):
fp = open("sahilsite/one.txt","r")
f = fp.read()
fp.close()
return HttpResponse(f)
Thanks dude.. That's what I needed
apke videoes and explaning ka tarika bhut hi majedar h ..keep on harry sir.
def index(request):
f=open("D:\\Django MA\\textutils\\textutils\\textutils\\info.txt")
c = f.read()
return HttpResponse(c)
Harry bhai work done successfully.
i was stuck with view and url you explained it perfectly
thankyou
Bhai well Done bhai kyaa Explain karte hoo bhaiiii puraaa......no questions remaining to do google after watching your Videos
Achha fir btao k dusre textiles tk kese pahuche
thank you so much harry, tumhari excitement aur passion k bayehse ye sikhne mein aur bhi majha ata hai
added below in Index function and worked like charm
def index(request):
f = open(r'C:\Users\kumarsan\PycharmProjects\DjangoCourse\TestUtils\textutils\textutils\Homepage.txt', 'r')
data = f.read()
return HttpResponse(data)
def index(request):
with open("1.txt","r") as f:
return HttpResponse(f)
Assignment done harry bhai
def index(request):
f = open("locoStart/1.TXT")
return HttpResponse(f.read())
f.close()
harry bhai big fan
I did Harry Bro yours last query...iwill...iam excited to doing this query...🙏
Harry Vai, this helps me a lot. I solved this problem by watching this video.
from django.shortcuts import render , HttpResponse
def temp(request):
return render(request, file.txt)
it may works !
i used this method
def file_content(request):
file = "C:\\Najam\\Web developement course\\Django Course\\one.txt"
with open(file, 'r', encoding='utf-8') as f:
read = f.readlines()
return HttpResponse(read)
cannot find any directory
plz guide brother
by the way I have tried too many web sites and channels to learn django but here I found it...love your cotent
views.py =
def index():
file = open('one.txt')
fh = file.read()
return HttpResponse(fh)
First I created one.txt where manage.py located
Then in views.py
def file(request):
with open('one.txt') as f:
return HttpResponse(f.read())
yes i also have to do the same giving file not found error in internal path
File can be opened with " with statement" is the best way.. Good choice buddy
tysm bro....it really helps me..
I am not getting it .Can u please xplain clearly
You are best Teacher Harry Bhai
from django.http import HttpResponse
def rf(response):
with open("filepath/one.txt") as f:
f1 = f.read()
return HttpResponse(f1)
we are going to raise the bar
Wow 👍 I'm very excited for next video. because every day i learn something new. Good job Harry bhai :)
We can read the txt file as text and store it as a string and we can use return HttpResponce with that string in our views.index function
Bruh
Mere pycharm me Ctrl + S press krne pr new development server generate nhi hora plz bataeya ke kese karu .
Mee Kae bar try kr Chuka
@@shubham6523 ctrl+s urls wale file me karne ke baad reload karo....agar ab bhi nahi hora to extensions install karo
samaj aa raha hai dhere dhere, Thanks Harray Bhaii
I have done the exercise by making a simple function using with open block and read the text file and save it in a variable and return it as a http response
Bhai ... Seriously..you have awsm.. teaching skills..
The way of explaination is from completely beginners to extremely advanced
Thanks a lot Harry bhaii😎
Thank you Harry Bhai - very simple and easy videos!
Harry Bhai successfully run ho Gaya , thank uh so much!
sol:
def index(request):
try:
f = open('name.txt', 'w')
f.write('Hello World, how are you?')
except Exception as e:
print(e)
try:
f = open('name.txt', 'r')
return HttpResponse(f.read())
except Exception as e:
print(e)
def txtfile(request):
with open("1.txt", "r") as f:
return HttpResponse(f.read())
from django.http import HttpResponse
def index(request):
f=open("textutils/1.txt")
filecontent=f.read()
return HttpResponse(filecontent)
from django.http import HttpResponse
def index(request):
with open("filepath/one.txt",'r') as f:
var = f.read()
return HttpResponse(var)
hoooooooooo gaya
learnt is first time without errors
thanks bro
You are amazing at explaining
I was able to complete your assignment using Path from pathlib and read the txt file stored in the same folder and manage,py and then passing the string into the return HTTPResponse function
def index(request):
file=open("terms.txt",'r')
return HttpResponse(file.readlines())
Can also use
with open
If Anyone Want to Set Color Scheme Like Harry Bhai, then You Should Change Color Scheme to Monokai
quiz ans = i will use open() to read file content and use that content in
Httpresponse
from django.http import HttpResponse
def display_file():
with open('abc.txt') as f:
for i in f:
return (i)
def index(request):
return HttpResponse(display_file())
def about(request):
return HttpResponse("about myself abc")
def index(request):
f = open('textutils/1.txt', 'r')
contents = f.read()
return HttpResponse(contents)
Bhai phle file open krenge read mode m uske bad read krenge
Aur store krayenge variable m
Fir pass kr denge httpresponse m
one of the besxt series
exercise ka ans-
views wale file mein:
def text(request):
readfile = open('test.txt')
areaded = readfile.readlines()
return HttpResponse(areaded)
aur urls wale file mein:
path('text/', views.text, name='text')
Texutils directory ke andhar ek aur directory kaise banaaya aapne
Harry bhai plzzz explain
def index(request):
with open("one.txt") as f:
return HttpResponse(f.read())
Def view (request):
File=open("io.txt",'r')
return HttpResponse(file.readlines())
Url patterns=[
path(' ',io )
]
I have some problem while executing. Can you help me so
Very Nicely Explain Harte ho!
Hands off!
You ARE UNDERRATED
def file(requet):
with open('one.txt','w') as f:
f.write("This is file content")
with open("one.txt") as f:
return HttpResponse(f.read())
path('', vfir.file, name='file')
def info(request):
file = open('filepath', 'r+')
Content= file.read()
return HttpResponse(Content, content_type='text/plain')
Bruh
Mere pycharm me Ctrl + S press krne pr new development server generate nhi hora plz bataeya ke kese karu .
Mee Kae bar try kr Chuka hu
harry bhai django tutorial very good
Harry bhai aap textutils ke andar dusri text utils par kaise aaye
han bhai samaj nhi aya muje b
Bro type { cd .\textutils\ } then enter
thank you so much harry. I loved every course of yours.
my inspiration sir love you
def index(request):
f = open("1.txt", "r")
f1 = f.readlines()
y = ""
for x in f1:
y += x
return HttpResponse(y)
You teach so well bro....god bless you
Bhai OP sikhata he tu ♥️♥️♥️....
First we will open it in read mode with "open" function and read the content with read function and then return it in html response....
from django.http import HttpResponse
def index(request):
fh=open('mywebsite/1.txt')
return HttpResponse(fh.read())
Hi herry,
1. Need to creat a file name one.py in current directory
2. Import that file in our urls.py
3.create one function inside the one.py file
4 . Save the program and the browser
ASSIGNMENT Solution :
def text(request):
f = open('./textutils/one.txt', 'r')
file_content = f.read()
f.close()
return HttpResponse(file_content, content_type="text/plain")
import os
def file_opening(request):
module_dir = os.path.dirname(__file__)
file_path = os.path.join(module_dir, '1.txt') #full path to text.
data_file = open(file_path , 'r')
data = data_file.read()
# context = {'rooms': data}
return HttpResponse(data)
This may help you
def index(request):
file = open('one.txt','r')
return HttpResponse(file.read())
You are Good Trainer Thanks For Making such tutorials
bhaai dil se shukriya ❣️
Sorry for delay thoda bahar chala gya tha. The approach will be to open the file first using open() method then read the contents of the file and save to a variable like content = f.read() then simply pass this content variable into the HttpResponse() method to display the actual content of the file. I tried with HTML code and it worked unexpectedly really well.
Hi Can you tell me the deailed answer of the quiz because its confusing me?
Im very new to it and i dont know the where i have to write this
path('about', views.about, name ='about')
^
SyntaxError: invalid syntax
@@dhaniyasumit1 Thanks
Def file1(request):
Test=open("hello.txt","r+")
return Http response(test.read())
test.close()
iam form Pakistan big fan sir love you
you always needs thumbs UP dude
Harry sir you are the best🙏
Harry Bhai?
Thank you... many many many Thank you
Read data from file,
def index(request):
file = open('1.txt', 'r')
content = file.read()
file.close()
return HttpResponse(content)
bhai muje .. bataoge ..
muje samaj nai aaya..
muje Question hi samaj nai aaya pls help
I Love you Harry...❤❤❤
bhai textutills k andar textutills file ko open karne k liye kya command hogi .becasuse jab m manage.py runserver kar rha hu to error aa rhah
def about(request):
txt_file=open(r"D:\Django_Project\project1\project1\1.txt",'r')
data=txt_file.read()
return HttpResponse(data)
def index(request):
try:
with open('1.txt', 'r+') as f:
data = f.read()
except Exception:
data = 'File is not present in the given directory'
return HttpResponse(data)
def index(request):
path = r"C:\Users\Asus\PycharmProjects\DjangoCourse\mysite\mysite\1.txt"
file = open(path, "r")
return HttpResponse(file.read())
Superb, simply wonderful... hats off to you, boy. keep it up.
Write in urls file this:
from . import txt, txt (Just below from statements)
path('', txt.index, name='1.txt')(Just below path statements)
Then write in txt file:
from django.http import HttpResponse
def index(request):
return HttpResponse("AVIK MAHESHWARI")
Thanks...... Best youtuber
def index(request):
with open('fun.txt','r') as f:
return HttpResponse(f.read())
def index(request)
file= open("1.txt"," ")
return HttpResponse(file.read())
FileNotFoundError at /
def web_doc(request):
f = open('mysite/hello.txt')
content = f.read()
return HttpResponse(content)
def read():
with open("read.txt",'r') as f:
File=f.read()
return HttpResponse(File)
I have save 1.txt inside the project even showing error file not found
@@tanishaagnihotri4954 you should check the path of the file or show the error you are facing...
@@punittiwari7557 thanks know its working
def about(request):
import os
file_path =os.path.join(os.getcwd(), "_one.txt")
with open(file_path) as f:
op = f.read()
return HttpResponse(op)
def index(request):
f=open('one.txt','r')
text=''"
for i in f:
text=text+i
return HttpResponse(text)
i thin we have to implement file handling concept of python eg: OPEN FILE using open() method then it should be read the content so matter=read() after that we can pass it in HttpResponse(matter) may be its work but am not sure.
Exception Value:
[Errno 2] No such file or directory: 'first.txt'
Use f = open('current-folder/1.text', 'r')
And in return HttpResponse(f.read())
@@BrighterWay will try it thanks buddy
@@BrighterWay great
Outstanding explanation 😍
create a static folder and create a .txt file and enter the path of the file and type /static/filename.txt and I would display it