[Hindi] Static and Templates folder - Web Development Using Flask and Python #3

In this video, I have explained the reason for using static and templates folder in Flask.

Flask uses its template folder for storing the raw templates which can be filled through the python program. The static folder on the other hand contains the public content like the images, css, javascript and other files. These files can also be viewed using the www.website-url/static address.

You can view the static folder of codewithharry website by going to static folder of this website as an exercise.

I hope you will like this video. Make sure to tell me what you think about this flask series and what you would like to see next in this series?

#tut1.py file as described in the video

from flask import Flask, render_template
app = Flask(__name__)

@app.route("/")
def hello():

    return render_template('index.html')

@app.route("/about")
def harry():
    name = "rohan das"
    return render_template('about.html', name2= name)
app.run(debug=True)

#index.html file as described in the video

<!DOCTYPE html>
<html>
<head>
	<title>Title of my page</title>
</head>
<body>
<img src="{{ url_for('static', filename='1.png') }}">


<p>In this video, I have shown you how to create a flask app using templates. I have used render template function from the Flask Module</p>
<p>Hope you will like this video!</p>

</body>
</html>

#about.html file as described in the video

<!DOCTYPE html>
<html>
<head>
	<title>Title of my page</title>
</head>
<body>

<h1>Hi I am {{ name2 }}!</h1>

<p>This is a way for me to teach you flask nicely</p>
</body>
</html>

Comments(10)

white_devil 8 months, 3 weeks ago
harry bhai mujhe problem ho raha hai yr course sickne me can you help me out plzzzzzzzzzzzzzzzzzzzzz
Ambikasharma 7 months, 3 weeks ago
Harry Bhai when i run this code it showing error-jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: index.html plz explain why it showing.
kashifraj 4 months, 1 week ago
harry bhai yeh error ara hy bar bar apka code b paste kar k dekah jinja2.exceptions.TemplateNotFound:index.html plz help meeee
pranshuk 2 months ago
bhai change the folder to "templates" this is only allowed
pranshuk 2 months ago
bhai change the folder to "templates" this is only allowed
saisworydash 2 months, 3 weeks ago
hey sir.. render_template q use hota hai? and what is render_template? can u please tell me ...!!??
Addicted48 2 months, 1 week ago
Harry Sir when i run this code it is showing an error-jinja2.exceptions.TemplateNotFound jinja2.exceptions.TemplateNotFound: index.html plz help me to solve it
Addicted48 2 months ago
guys,if you are facing an error,Template not found,index.html it is bcoz,you are writing folder name "template" instead of "templates" in show exploarer,fix tht error nd good to go
kuntal2020 3 weeks, 4 days ago
Still getting such error, when i use app.run(debug=True), flask gets stuck. Only using app.run() is working. But any change made in index.html, is not reflected on browser. Plus even after creating bootstrap.html, it is not being found using /bootstrap, I'm getting error 404 not found.
anwalarif786 3 weeks, 4 days ago
127.0.0.1 - - [08/Jun/2020 20:37:22] "GET / HTTP/1.1" 500 - Traceback (most recent call last): File "C:\python3.8\Lib\site-packages\flask\app.py", line 2464, in __call__ return self.wsgi_app(environ, start_response) File "C:\python3.8\Lib\site-packages\flask\app.py", line 2450, in wsgi_app response = self.handle_exception(e) File "C:\python3.8\Lib\site-packages\flask\app.py", line 1867, in handle_exception reraise(exc_type, exc_value, tb) File "C:\python3.8\Lib\site-packages\flask\_compat.py", line 39, in reraise raise value File "C:\python3.8\Lib\site-packages\flask\app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "C:\python3.8\Lib\site-packages\flask\app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\python3.8\Lib\site-packages\flask\app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\python3.8\Lib\site-packages\flask\_compat.py", line 39, in reraise raise value File "C:\python3.8\Lib\site-packages\flask\app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "C:\python3.8\Lib\site-packages\flask\app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "C:\Users\hp\PycharmProjects\flask_tut\tut1.py", line 5, in hello return render_template('index.html') File "C:\python3.8\Lib\site-packages\flask\templating.py", line 138, in render_template ctx.app.jinja_env.get_or_select_template(template_name_or_list), File "C:\python3.8\Lib\site-packages\jinja2\environment.py", line 930, in get_or_select_template return self.get_template(template_name_or_list, parent, globals) File "C:\python3.8\Lib\site-packages\jinja2\environment.py", line 883, in get_template return self._load_template(name, self.make_globals(globals)) File "C:\python3.8\Lib\site-packages\jinja2\environment.py", line 857, in _load_template template = self.loader.load(self, name, globals) File "C:\python3.8\Lib\site-packages\jinja2\loaders.py", line 115, in load source, filename, uptodate = self.get_source(environment, name) File "C:\python3.8\Lib\site-packages\flask\templating.py", line 60, in get_source return self._get_source_fast(environment, template) File "C:\python3.8\Lib\site-packages\flask\templating.py", line 89, in _get_source_fast raise TemplateNotFound(template) jinja2.exceptions.TemplateNotFound: index.html 127.0.0.1 - - [08/Jun/2020 20:37:22] "GET /?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 - 127.0.0.1 - - [08/Jun/2020 20:37:22] "GET /?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 - 127.0.0.1 - - [08/Jun/2020 20:37:22] "GET /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 - 127.0.0.1 - - [08/Jun/2020 20:37:22] "GET /?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1" 200 - 127.0.0.1 - - [08/Jun/2020 20:37:22] "GET /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 - 127.0.0.1 - - [08/Jun/2020 20:37:22] "GET /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 - error hi error bhai

Resources

No downloadable resources for this video. If you think you need anything, please post it in the QnA!

Course Announcements

Any Course related announcements will be posted here

Course Content