Python Django : Create Web page Html, View and Render (2nd Tutorial)
Автор: 6 Dimension Technology
Загружено: 2020-02-02
Просмотров: 122
Welcome to Python Django : Create Web page (Html), View and Render (2nd Tutorial)
1. Make sure you viewed, Create Web App (1st Tutorial) video in youtube.
Note* Django Project and Web App is already created
Steps :
1. Open setting.py file (pdproject/settings.py) and look for INSTALLED_APPS and add your App name (pdapp).
2. Create Web Templates. At App folder, create a folder name 'Templates' and inside this folder, create another folder with the same name as App name 'pdapp'. The folder tree should look like this (pdapp/templates/pdapp).
3. Now create base.html,index.html and about.html (Samples) file in (pdapp/templates/pdapp(here)) folder.
Note* you may create as many files as you want based on your Web project.
4. Now write simple html script into your html pages. (I already have some snippets)
base.html (Master Page),
at nav link (href) enter this code.
{% url 'Home' %}
at (body) after navbar html script enter this code.
{% block content %} {% endblock content %}
index.html (Main Page) and about.html page, enter this code.
{% extends "pdapp/base.html" %}
{% block content %}
(content html scripts here)
{% endblock content %}
5. then create views to render the html pages.
example:
def base(request):
return render(request, 'pdapp/base.html')
6. then create urls.py file (New file at pdapp/urls.py) and import path and views add urlpatterns as to navigate the pages.
example:
from django.urls import path
from pdapp import views
urlpatterns = [
path('', views.index, name='Home'),
path('about', views.about, name='About'),
]
7. then add the App path at urls.py file (pdproject/urlspy)
example:
path('pdapp/', include('pdapp.urls')),
Note* to make the landing page direct to host address, remove the App name from urls.py (pdproject/urlspy).
8. then runserver (python manage.py runserver)
9. go to http://127.0.0.1:8000/ or http://localhost:8000/
Thank You
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: