Excises—using template to show help page Link to heading
- create new app
django-admin startproject ProTwo
python manage.py startapp AppTwo
- create new
templatesfolder in project folder
in this way, django knows where to find these templates
- create new html template
under templates folder, we create a new html file(create new folder for app and create new html file into that folder)
in the new html file, we can use template tags(a.k.a Django Template Variable) that pass content into this template to show.
{{ insert_me }}
- Hook template tags to views
in views.py in app folder, use dictionary to render
what does that mean?
my_dict = {'insert_me': "Hello, this is from views.py",}
and from views, we return render()
- create
urls.pyin AppTwo
By creating urls.py in AppTwo, we keep the best effort to make the app clean.
- modifying
settings.pyin project folder
add TEMP_DIR into file, TEMP_DIR is the directory that we want to tell django
TEMP_DIR = os.path.join(BASE_DIR, "templates")
then add TEMP_DIR into DIR parameter under TEMPLATES
- routings configs
in project folder, urlpatterns is for routing. add for example url(r'^first_app$', include('first_app.urls')) in this case, when people input www.mydomain.com/first_app, then it will go to the app’s folder to search for routing action. and in app’s urls.py, it can link the views.py for further information.